Currently I want to warn my players a shutdown is incoming.
My code is
game:BindToClose(function()
ClosingGame = true
--if game:GetService("RunService"):IsStudio() then return end
MessageService:PublishAsync("ServerDeleted", {game.JobId})
for _,pl in ipairs(game.Players:GetPlayers()) do
wait(0.5)
local playerFolder = game.ServerStorage.PlayerData:FindFirstChild(pl.Name.."_Data")
if not playerFolder then return end
playerFolder.Parent = nil
local joind = pl.TimeJoined.Value
playerFolder.LastPlayed.Value = os.time()
playerFolder.TimePlayed.Value = playerFolder.TimePlayed.Value + playerFolder.SessionTime.Value
saveData(pl,playerFolder)
end
local msg = Instance.new("Message")
msg.Text = "Server is shutting down in 15 seconds..."
msg.Parent = workspace
task.wait(15)
print("Shutting Down")
end)
It is neither waiting the 15 seconds nor creating the message. It is simply saving player data.
Anyone has a solution for this?