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

How do I make a server shutdown or kick all players?

Asked by 4 years ago

I wanted to make my game server shutdown or kick all players when one of the player leave the server, how can I do that and let all the players see a text with reason?

game.Players.PlayerRemoving:Connect(function(plr) for i,v in pairs(game.Players:GetPlayers()) do v:Kick("You have been kicked because one of the player left the game") end)

I am noob with script and that's all what I tried with my game :/

1 answer

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Why exactly do you want to kick the players when someone leaves the game? Sounds like you'd have a lot of trolls going into servers and ending games like that.

The logic in your code is fine, just needed an 'end' after the for loop to end the loop. Here's how you'd do it:

local Players = game:GetService("Players")

Players.PlayerRemoving:Connect(function(plr)
    for i,v in pairs(game.Players:GetPlayers()) do 
        v:Kick("You have been kicked because a player left the game") 
    end
end)
0
my game is a 3 player cooperation game,if one of the player leave the game when the others are playing,they will be stuck in the game,and the new player who join the game cannot follow their part,then the players can't play the game as well. markh442 2 — 4y
0
however,thanks a lot for answering. markh442 2 — 4y
0
and it's worked, thanks again! markh442 2 — 4y
0
That's fair, but I think if you lose a player, you should tell the players that a player left and wait for another player so it isnt as much of an annoyance. royaltoe 5144 — 4y
View all comments (2 more)
0
but the players can't get to the part without the help of other players,and there are checkpoints in the game so the players can't get back to the place where they start. markh442 2 — 4y
0
How about restarting the game and putting them in some sort of in game lobby until someone else joins royaltoe 5144 — 4y
Ad

Answer this question