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
local playeryouwanttoshutdownafterheleaves = "robert" game.Players.PlayerAdded:Connect(function(player) --does nothing lol end) game.Players.PlayerRemoving:Connect(function(player) if player == playeryouwanttoshutdownafterheleaves then for i,v in pairs(game.Players:GetChildren()) do v:Kick("This game has been shutdown because "..playeryouwanttoshutdownafterheleaves.." leaved. Sorry for the inconvenience.") end end 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.
function shutdown() game.Players.ChildAdded:connect(function(h) h:Kick() end) for _,i in pairs (game.Players:GetChildren()) do i:Kick() end 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).