Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to check if player id is in an array?

Hi, I'm making an anti-cheat and I want to have users who are ignored in the anti-cheat, I have ID's in an array and I just need to check if a player id is in the array. I currently have

local AdminIDS = {109811710} -- My ID

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Character = player.Character
		local RootPart = Character.HumanoidRootPart
		
		while wait() do
			--Speed Detection--
			local Pos1 = RootPart.Position
			wait()
			local Pos2 = RootPart.Position
			local difference = ((Pos1 - Pos2) * Vector3.new(1, 0, 1)).Magnitude -- for speed hacking
			local Ydifference = ((Pos1 - Pos2) * Vector3.new(0, 1 ,0 )).Magnitude -- For jump hacking maybe

			if difference > 1.7 then -- checks if the user moved too much
				RootPart.Position = Pos1
			end
		end
	end)
end)

I want to check if the player.UserId is in the AdminIDS table, I have tried if has_value(AdminIDS, player.UserId) but that function doesn't exist. Any help is greatly appreciated

1 answer

local AdminIDS = {109811710} -- My ID
local function CheckIfAdmin(UserID)
 	--Loops through each item in array and checks if the Plr UserID Matches one of the items in the array
	for _,v in pairs(AdminIDS) do
		if v == UserID then
			return true
		end
	end
	--Since nothing was returned it returns false
	return false
end

local IsAdmin = CheckIfAdmin(player.UserId)
if IsAdmin == true then
	print(player .. " Is an admin")
elseif IsAdmin == false then
	print(player .. " Is not an admin")
end

2 comments

0

Better, use table.Find(AdminIDS, UserID)

0

table.Find(AdminIDS, UserID) If it finds and matching id, it will return the index, if not it will return nil, soo just do if table.Find(AdminIDS, UserID) then print("Found")

This discussion is preserved as it was. New answers, comments, and votes are closed.