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

Why isn't this ban script working? [closed]

Asked by 9 years ago

I don't know why this isn't working, but I have no errors, and it doesn't work.

Script:

game.Players.PlayerAdded:connect(function(plr)
    if plr.Name == "Player" then
        plr:Destroy()
    end
end)

Locked by sgsharp and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

This is probably because your player's name ISNT going to be 'Player'.

Another potential script breaker could be the lack of a yeild before you check the plr's name.

Lastly, rather than destroying the player instance there is a method for kicking players, called 'Kick'

local bannedName = "Player" --change this

game.Players.PlayerAdded:connect(function(plr)
    wait(.5)
    if plr.Name == bannedName then
        plr:Kick()
    end
end)

Additionally, you should use a table to define banned players. Then iterate through the table and kick the player if the names match.

local bannedNames = {"Player","Goulstem","Noob","PersonYouHate"}

game.Players.PlayerAdded:connect(function(plr)
    wait(.5)
    for i,v in pairs(bannedNames) do
        if v == plr.Name then
            plr:Kick()
        end
    end
end)

Note: This should be used from a server script

And a last thoughts..

1) Try banning from player's userId for cases where if the player were to change their name, the ban list would still be accurate.

2) Try banning from DataStores for auto-updating ban lists.

Ad
Log in to vote
2
Answered by 9 years ago
game.Players.PlayerAdded:connect(function(plr) --When player joins.
    if plr.Name == "Player" then --If their name is player
        plr:Kick() --Kick player
    end -- Ends.
end)

This is a server-side script. Use the kick method instead. Kick Method.