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

Banned system table, variable error?

local banned = {'danyopera','mainmodul'}

game.Players.PlayerAdded:connect(function(player) if player == banned then game.Players.LocalPlayer:kick'Banned!' end end)

2 answers

Banned is a table, so you can't say if the player is equal to a table. Since there's no lua function for checking if an item is in a list, you can just loop over the list and see if the player matches any of the entries.

local banned = {'danyopera','mainmodul'}

game.Players.PlayerAdded:Connect(function(players)
	for i, name in pairs(banned) do
		if player.Name == name then
			player:kick("Banned!")
		end
	end
end)

You're using a dictionary here, which isn't ideal, but it could allow for the following code to work:

local banned = {'danyopera','mainmodul'}

game.Players.PlayerAdded:Connect(function(players)
	if banned[player.Name] then
		player:kick("Banned!")
	end
end)

I'm not sure if it's player.Name or just player, but if you experiment a bit it should work.

4 comments

0

This wouldn't work banned[player.Name] would search for key of player.Name. In the table the names are Values of numerical keys. danyopera = 1, mainmodul = 2.

0

ima test it later

0

Sorry about that I've gotten a bit used to python

0

It should still work though right? Since if the player wasn't in the list it would return a nil value

You can use table.find() to check if the player's name is in the table, it'll return nil if it cannot find the value specified inside the table, or it'll return the index position of that value.

local banned = {'danyopera','mainmodul'}

game.Players.PlayerAdded:Connect(function(Player)
	
	if table.find(banned, Player.Name) then
		Player:Kick('Banned!')
	end
end)

If you're going to implement a ban system in your game I wouldn't recommend using the players' name though, I'd recommend using their UserId which is a unique ID every account has upon creating their account. If a player changes their account name, their name won't be the same as the name inside the table anymore so they will be able to join. Their UserId cannot be changed in any way so it's recommended to use their UserId instead.

1 comment

0

this can work ty

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