My Server is printing this when I exit my game:
19:29:02.636 - Not running script because past shutdown deadline.
Any Tips?
Here's my script:
local datastores = game:GetService("DataStoreService"):GetDataStore("MoneyDataStore") local deafultCash = 0 local playersLeft = 0 game.Players.PlayerAdded:Connect(function(player) playersLeft = playersLeft + 1 local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new ("IntValue") money.Name = "Money" money.Value = 0 money.Parent = leaderstats -- Data Stores local player_data pcall(function() player_data = datastores:GetAsync(player.UserId.."-Money") end) if player_data ~= nil then -- Player Has Saved Data money.Value = player_data else --New Player money.Value = deafultCash end end) local bindabaleEvent = Instance.new("BindableEvent") game.Players.PlayerRemoving:Connect(function(player) pcall(function() datastores:SetAysnc(player.UserId.."-Money",player.leaderstats.Money.Value) print("Saved") playersLeft = playersLeft - 1 bindabaleEvent:Fire() end) end) game:BindToClose(function() -- This Will be triggerd upon shutdown while playersLeft > 0 do bindabaleEvent.Event:Wait() end end)
My best guess is that the bindable event isn't firing (and/or playersLeft is still greater than 0), so at some point Roblox terminates the script (since it will only allow BindOnClose to run for at most 30 seconds).
I'd like to point out that if the SetAsync
datastore call fails, playersLeft will permanently be above 0, which would cause the behaviour I just described.
(Edit)
You won't see any output if something errors in a pcall - you can check what it returns (it returns 'success, returnValueOrErrorMsg') and print out the error msg like this:
game.Players.PlayerRemoving:Connect(function(player) local success, msg = pcall(function() datastores:SetAysnc(player.UserId.."-Money",player.leaderstats.Money.Value) print("Saved") end) if not success then print("Saving failed:", msg) end playersLeft = playersLeft - 1 bindabaleEvent:Fire() end) end)
Notice how 'playersLeft' decreases even if the saving fails.