I only want it to shut down one person. Not all. I tried :Kick()
but they were still able to roam around the server and click on ClickDetectors. How would I make their game crash or shutdown?
01 | -- Server side... |
02 | local PlayersTable = { 'Player1' , 'Player2' } |
03 |
04 | function Disconnect(Plr) |
05 | for _,v in pairs (PlayersTable) do |
06 | if v = = Plr then |
07 | v:Kick() |
08 | end |
09 | end |
10 | end |
11 |
12 | --Example : |
13 |
14 | Disconnect( "Player1" ) |
15 |
Try this:
01 | local Shutdown = false ; |
02 |
03 | --// Shutdown server |
04 | for _,Player in pairs (game.Players:GetPlayers()) do |
05 | Player:Kick() |
06 | Shutdown = true |
07 | end |
08 |
09 | --// Prevent new players joining |
10 | game.Players.PlayerAdded:connect( function (Plr) |
11 | if Shutdown then |
12 | Plr:Kick() |
13 | end |
14 | end ) |
As stated on the wiki, the Kick method disconnects the player from the game.
To disconnect certain people, a table must be used.
banned = {"Noob", "AnnoyingGuest"}
To add to the table over time simply insert a comma(Unless the table is empty) and a string of the player's name.
Now to simulate the banning phase the PlayerAdded event must be called. Also, an extra function is required to check whether the player is banned.
01 | banned = { "Noob" , "AnnoyingGuest" } |
02 |
03 | function isBanned(name) |
04 | for i,v in pairs (banned) do |
05 | if v:lower() = = name:lower() then |
06 | return true |
07 | end |
08 | end |
09 | return false |
10 | end |
11 |
12 | game.Players.PlayerAdded:connect( function (plr) |
13 | if isBanned(plr.Name) then plr:Kick() end |
14 | end ) |