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

Why wont this work correctly?

local List = {'Player', 'UltraUnitMode'}

game.Players.PlayerAdded:connect(function(plr)
if plr.Name == List then
return true
elseif plr.Name ~= List then
plr:Destroy()
end
end)

3 answers

✓ Accepted answer

You need to loop through the table using a for loop.

Code:

game.Players.PlayerAdded:connect(function(plr)
	local success = false
	for i,v in pairs(List) do
		if v == plr.Name then
			success = true
		end
	end
	if not success then
		plr:Destroy()
	end
end)

List is literally a list. How could your name ever equal a list? That makes no sense.

What you want to do is find if your name is inside the list.

We could use a for loop to compare each item to your name, writing a function like this:

function isInList(name)
	for i, v in pairs(List) do
		if name == v then
			return true
		end
	end
end

But an easier method would be to make use of dictionaries;

local List = {
["Player"] = true,
["UltraUnitMode"] = true
}

game.Players.PlayerAdded:connect(function(plr)
	if not List[plr.Name] then --if you're not in the list
		plr:Kick() --use kick() instead of destroy()
	end
end)

2 comments

1

:p put a comma on the first element in table

0

oh my bad lol

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