Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Any tips when getting this error: Not running script because past shutdown deadline?

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)

1 answer

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.

4 comments

0

Do you have any places I should edit my script in?

0

It was that I misspelled Async in the one infront of playersLeft = playersLeft - 1

0

It has no errors but its still not saving the data!

0

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.Valu

This discussion is preserved as it was. New answers, comments, and votes are closed.