Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make the server shut down through a script?

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.

2 answers

✓ Accepted answer

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.

3 comments

0

i know its not a request site, i didnt have the knowledge to find what it was. ill have to see if it works later, because its raining and my internet doesnt work very well when it rains.

0

"leaved" should be "left"

0

im not from usa, sorry

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).

This discussion is preserved as it was. New answers, comments, and votes are closed.