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

How to make the server shut down through a script?

Asked by 4 years ago

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

Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
4 years ago

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.

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. AbsurdAwesome101 56 — 4y
0
"leaved" should be "left" Geobloxia 251 — 4y
0
im not from usa, sorry RAFA1608 543 — 4y
Ad
Log in to vote
0
Answered by
P3tray 0
4 years ago

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

Answer this question