Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Banned system table, variable error?

Asked by 3 years ago

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

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

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

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. CrunchChaotic 139 — 3y
0
ima test it later mainmodul 45 — 3y
0
Sorry about that I've gotten a bit used to python thecelestialcube 123 — 3y
0
It should still work though right? Since if the player wasn't in the list it would return a nil value thecelestialcube 123 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
this can work ty mainmodul 45 — 3y

Answer this question