How to make a shutdown-game script?

:green_circle: This topic has been solved.

1 Like

Help would be appreciated…!

Please?

You never actually called the function, just put this at the bottom of your script, or wherever you want in your script:

ShutdownServer()

I copy and pasted your script in a test environment and it works perfectly fine:

1 Like

I have just tried your code and added the call for the function, and it works, make sure it is in a Script, not a LocalScript and I recommend adding it into ServerScriptService

local Players = game:GetService("Players")

local function ShutdownServer()
	for i, Player in pairs(Players:GetPlayers()) do
		local m = Instance.new("Message")
		m.Parent = game.Workspace
		m.Text = "⚠ This server is closing."
		wait(5)
		m:Destroy()
		Player:Kick("This server has closed.")
	end

	Players.PlayerAdded:Connect(function(Player)
		Player:Kick("This server has closed.")
	end)
end

ShutdownServer()
1 Like

@TheReal4Cedar123 @timtim

What I mean is:

  • Is there a way I can let some staff members type like ‘/shutdown’ in chat and it closes the server
  • Or is it not possible without typing it in console?

You can get the message a player said and his Id and check if it is a staff member and after check if the message was “/shutdown” !
I hope that was helpful !

1 Like

As @FireStrykerAzul said, here is some of what you need to do

.Chatted:Connect(function(msg) 
	if msg:lower() == "/shutdown" then
		ShutdownServer()
	end
end)
1 Like

You can do this by clicking the three dots next to your game’s name on the website, and hitting shutdown all servers.


You can use PlayerAdded, and use Player.Chatted for that:

local admins = {
 -- UserIDs here
}

game.Players.PlayerAdded:Connect(function(plr)
    if table.find(admins, plr.UserId) then
        plr.Chatted:Connect(function(content)
            if content:lower() == '/shutdown' then
                shutdown()
            end
        end)
    end
end)
2 Likes

Now what the heck does that mean?

1 Like

I’m either blind, or, it’s because of code above, due to a function not being properly closed. What’s at line 7?

Show us the entire code !

This text will be blurred

You forgot to put to close the function at line 7 and close to if statement at line 20, are u reading the error?

Add a return before the ShutdownServer(), if it doesn’t work, remove the () to ShutdownServer()

Send it not the image please !

Close the function at line 7, so put an end at line 16.

Nevermind it works.

Thank you everyone for helping! Especially @FireStrykerAzul @GibusWielder and @
@TheReal4Cedar123!

Final Code
print("'/shutdown' command loaded.")

local Players = game:GetService("Players")

local admins = {"TeamDreams123", "Tr6deJJ","Mainaccwontworkspare"}

local function ShutdownServer()
	for i, Player in pairs(Players:GetPlayers()) do
		local m = Instance.new("Message")
		m.Parent = game.Workspace
		m.Text = "⚠ This server is closing, please rejoin."
		wait(5)
		m:Destroy()
		Player:Kick("⚠ This server has closed.")
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(admins, plr.Name) then
		plr.Chatted:Connect(function(content)
			if content:lower() == '/shutdown' then
				ShutdownServer()
			end
		end)
	end
end)

:heart:

2 Likes

Add an end at line 16.

Try the script that I posted but with a tiny difference.

At line 21, I added a return before the function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.