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

Why does my datastorage pause the script?

Asked by 3 years ago

for some reason, on the first pcall, the script doesn't run after it because it doesn't print hi. Why is it like this?

game.Players.PlayerRemoving:Connect(function(player)
    --[1] = coins
    --[2] = Best Time
    --[3] = Worst Time
    local leaderstats = {}

    table.insert(leaderstats,#leaderstats+1,player.leaderstats.Coins.Value)
    table.insert(leaderstats,#leaderstats+1,player.leaderstats["Best Time"].Value)
    table.insert(leaderstats,#leaderstats+1,player.leaderstats["Worst Time"].Value)

    local success, errormessage = pcall(function()
        DataStore:SetAsync(player.UserId,leaderstats)
    end)
    print("Hi")
    if not success then
        warn(errormessage)
    end
    --halos
    local tools = {}
    for _, halos in ipairs(game.ServerStorage.HaloInventory[player.Name]:GetChildren()) do
        table.insert(tools,#tools + 1,halos)
        print(halos)
    end

    local success4, errormessage4 = pcall(function()
        HaloStore:SetAsync(player.UserId, tools)
    end)

    if success4 then
        game.ServerStorage.HaloInventory[player.Name]:Destroy()
        game.ReplicatedStorage.HaloInventory[player.Name]:Destroy()
    else
        warn(errormessage4)
    end
end)

Answer this question