This topic has been solved.
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:
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()
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 !
As @FireStrykerAzul said, here is some of what you need to do
.Chatted:Connect(function(msg)
if msg:lower() == "/shutdown" then
ShutdownServer()
end
end)
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)
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)
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.