local banned = {'danyopera','mainmodul'}
game.Players.PlayerAdded:connect(function(player) if player == banned then game.Players.LocalPlayer:kick'Banned!' end end)
local banned = {'danyopera','mainmodul'}
game.Players.PlayerAdded:connect(function(player) if player == banned then game.Players.LocalPlayer:kick'Banned!' end end)
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.
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.
this can work ty
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
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.
ima test it later
Sorry about that I've gotten a bit used to python
It should still work though right? Since if the player wasn't in the list it would return a nil value