local noclipStatus = {} -- Table to store the noclip status for each player

hook.Add("PlayerButtonDown", "ULXCustomNoclipKeyPress", function(ply, button)
    if button == KEY_V then -- KEY_V is the numeric value for the "V" key
        if ULib.ucl.authed[ply:UniqueID()] then
            local isAdmin = ply:IsAdmin()
            local isAllowedGroup = ply:GetUserGroup() == "admin" -- Replace "your_admin_group" with the name of your admin group

            if isAdmin or isAllowedGroup then
                if noclipStatus[ply] then
                    ply:ConCommand("ulx noclip") -- Turn off noclip
                    noclipStatus[ply] = false
                else
                     -- Turn on noclip
                    noclipStatus[ply] = true
                end
            end
        end
    end
end)

-- Reset noclip status when player spawns or joins
hook.Add("PlayerSpawn", "ULXResetNoclipStatus", function(ply)
    noclipStatus[ply] = false
end)

-- Reset noclip status when player disconnects
hook.Add("PlayerDisconnected", "ULXResetNoclipStatusOnDisconnect", function(ply)
    noclipStatus[ply] = nil
end)