Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited by chess123mate 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
Do you have any places I should edit my script in? tyorange09 4 — 4y
0
It was that I misspelled Async in the one infront of playersLeft = playersLeft - 1 tyorange09 4 — 4y
0
It has no errors but its still not saving the data! tyorange09 4 — 4y
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 tyorange09 4 — 4y
Ad

Answer this question