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

How to solve "Not running script because shutdown deadline"?

Asked by 4 years ago

Hi So I've, again, been following an AlvinBlox tutorial. The part i need help in is the saving the currency, weapons and equipped weapon.

local dataStores = game:GetService("DataStoreService"):GetDataStore("BucksDataStore")
local defaultCash = 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 bucks = Instance.new("IntValue")
    bucks.Name = "Bucks"
    bucks.Value = 0
    bucks.Parent = leaderstats

    local playerData = Instance.new("Folder")
    playerData.Name = player.Name
    playerData.Parent = game.ServerStorage.PlayerData

    local equipped = Instance.new("StringValue")
    equipped.Name = "Equipped"
    equipped.Parent = playerData

    local inventory = Instance.new("Folder")
    inventory.Name = "Inventory"
    inventory.Parent = playerData

    player.CharacterAdded:Connect(function(character)

        character.Humanoid.WalkSpeed = 16
        character.Humanoid.Died:Connect(function()

            if character.Humanoid and character.Humanoid:FindFirstChild("creator")then
                game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." Killed "..player.Name
            end

            if character:FindFirstChild("GameTag") then
                character.GameTag:Destroy()
            end

            player:LoadCharacter()

        end)

    end)

    -- Data Stores

    local player_data
    local weaponsData
    local equippedData

    pcall(function()
        player_data = dataStores:GetAsync(player.UserId.."-Bucks")
    end)

    pcall(function()
        weaponsData = dataStores:GetAsync(player.UserId.."-Weps")
    end)

    pcall(function()
        equippedData = dataStores:GetAsync(player.UserId.."-EquippedValue")
    end)

    if player_data ~= nil then
        -- Player has saved data
        bucks.Value = player_data
    else 
        -- New Player
        bucks.Value = defaultCash
    end

    if weaponsData then

        -- For loop though weapons saved
        -- Load them in
        -- Set the equipped value

    end

end)

local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:Connect(function(player)

    pcall(function()
        dataStores:SetAcync(player.UserId.."-Bucks",player.leaderstats.Bucks.Value)
        print("Saved")
        playersLeft = playersLeft - 1
        bindableEvent:Fire()
    end)

end)

game:BindToClose(function()
    while playersLeft > 0 do
        bindableEvent.Event:Wait()
    end
end)

When I run this, an error appears saying: Not running script because shutdown deadline.

Thanks for all the help lately. Thank you in advance

Answer this question