Why can u use game:Shutdown() in studio but not real game?

Hello there, when i was messing around with coregui i wanted to test the game:Shutdown(). when i did it actually worked in studio not in a actual game server. But why cant it work in a game server but i works in studio?

1 Like

Could you explain a bit more? Show us the script you’re using.

1 Like

game:Shutdown()? here lemme show u a quick vid.

robloxapp-20200728-1818128.wmv (271.0 KB)

https://developer.roblox.com/en-us/api-reference/function/DataModel/Shutdown

image

1 Like

If you want to shut down a server inside of your game, do this:

local Players = game:GetService("Players")

local Admins = {YourUserIDHere,AnotherHere,etc}

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(msg)
		if msg:lower() == "/shutdown" then
			for index,value in ipairs(Admins) do
				if Player.UserId == Admins[index] then
					for index,value in ipairs(Players:GetPlayers()) do
						value:Kick("\nServer has been shut down")
					end
				end
			end
		end
	end)
end)
4 Likes

Make sure to mark his as the solution :ok_hand:

Last note:
You can just do a for loop on all players then :Kick()?
Yea it might not work the same but still gets the job done.

1 Like

Eh, i put a engine post on why we should be able to use that command.

I’d recommend replacing pairs with ipairs as GetPlayers() and the ‘Admins’ table is an array.
ipairs runs faster and is meant for arrays.

2 Likes