-- Define the list of allowed groups
local allowedGroups = {
    ["superadmin"] = true,
    ["admin"] = true,
    ["owner"] = true,
    -- Add more allowed groups here as needed
}

local noclipStatus = {} -- Table to store the noclip status for each player

hook.Add("PlayerButtonDown", "CustomNoclipKeyPress", 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 isAllowedGroup = allowedGroups[ply:GetUserGroup()]

            if 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", "ResetNoclipStatus", function(ply)
    noclipStatus[ply] = false
end)

-- Reset noclip status when player disconnects
hook.Add("PlayerDisconnected", "ResetNoclipStatusOnDisconnect", function(ply)
    noclipStatus[ply] = nil
end)
