All i need is a line of code that can shut down the game when run through a script. I was making a UTG sandbox, but some utgs can break the whole server so I wanted a script that would shut down the server when the player leaves.
this is NOT a request site but whatever here goes
01 | local playeryouwanttoshutdownafterheleaves = "robert" |
02 | game.Players.PlayerAdded:Connect( function (player) |
03 | --does nothing lol |
04 | end ) |
05 | game.Players.PlayerRemoving:Connect( function (player) |
06 | if player = = playeryouwanttoshutdownafterheleaves then |
07 | for i,v in pairs (game.Players:GetChildren()) do |
08 | v:Kick( "This game has been shutdown because " ..playeryouwanttoshutdownafterheleaves.. " leaved. Sorry for the inconvenience." ) |
09 | end |
10 | end |
11 | end ) |
this shall do. but still, this isnt a request site.
The best way is to kick all new players on join, as roblox shuts down the server when the last player leaves. This script forces all players to disconnect when a new player join, and all existing players.
1 | function shutdown() |
2 | game.Players.ChildAdded:connect( function (h) |
3 | h:Kick() |
4 | end ) |
5 | for _,i in pairs (game.Players:GetChildren()) do |
6 | i:Kick() |
7 | end |
8 | end |
P.S. Please display better research on the topic, and any code you have tried. This is not a request website. It is designed to HELP people, not do it for them (this one was just easy).