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

Why wont this game:BindToClose(function() script not work!!??

Asked by 5 years ago
Edited 5 years ago

You probably have seen something like this before, essentially i'm trying to kick the players before the server shuts down. The problem is it doesnt kick the player, and it prints "???" when it should kick me BEFORE printing that. Anyone have any ideas why this wont work???

game:BindToClose(function()
    for i, player in ipairs(game.Players:GetChildren()) do
        player:Kick("The Game Is Shutting Down, Please Rejoin")
    end
    print("???")
    wait(5)
end)
0
Just a side note you should be using GetPlayers and not GetChildren. However the BindToClose method is called when the server shuts down, usually when the last player in a server leaves, maybe that's why it didn't kick. User#19524 175 — 5y
0
it prints "???" and then waits 5 seconds before the server shuts down though KamikazeJAM108867 38 — 5y
0
Can you suggest an alternative script because its clear this one doesn't work KamikazeJAM108867 38 — 5y

1 answer

Log in to vote
0
Answered by
Syclya 224 Moderation Voter
5 years ago
Edited 5 years ago

Note that you can only use this once in the game. Also, try this instead:

game:BindToClose(function()
for _,v in pairs(game:GetService("Players"):GetPlayers()) do
v:Kick("Game is shutting down...")
end
end)
0
Nope, just says Developer Has shut down servers... KamikazeJAM108867 38 — 5y
Ad

Answer this question