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

Value of my IntValue object changes but when I reference it in a scrip it still shows 0?

Asked by
Zrxiis 26
4 years ago
Edited 4 years ago

I put strength, intelligence, defense, and health stat values in a folder in the player call playerstats and in another local script when a player levels up and adds points to that stat its suppose to go up which it does when I check the value, but when I try to save it using a script in serverscriptservice the values show up as 0.

local function savePointAllocation(player)
    local playerstats = player.PlayerStats
    local str = playerstats:FindFirstChild("Strength")
    local def = playerstats:FindFirstChild("Defense")
    local int = playerstats:FindFirstChild("Intelligence")
    local hp = playerstats:FindFirstChild("Health")
    local success, err = pcall (function()
        local newStatValues = {
                Strength = str.Value,
                Defense = def.Value,
                Intelligence = int.Value,
                Health = hp.Value 
        }
        plrStats:SetAsync(player.UserId.."Stats",newStatValues) 
    end)

    if success then
        print("Point allocation successfully saved!")
    elseif not success then
        repeat
            print(err)
            local newStatValues = {
                Strength = str.Value,
                Defense = def.Value,
                Intelligence = int.Value,
                Health = hp.Value 
            }
            plrStats:SetAsync(player.UserId.."Stats",newStatValues)
        until success
    end
end
game.Players.PlayerRemoving:Connect(function(player)
    savePointAllocation(player)
end)
0
Is this a localscript? proqrammed 285 — 4y
0
its a script inside the serverscripservice Zrxiis 26 — 4y

1 answer

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

The classic you forgot game:BindToClose().

Basically before your datastore can successfully store all data the game server has already shutdown and terminates the datastore process. However if you use game:BindToClose(), loop through all remaining players in the game and save the data for each of the players at that point, then the game will wait until the saving has been handled and then exit the game.

The wiki explains this exact issue aswell:

https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose

0
the game server isn't shutting down and not saving, it's that when it gets the values from the player stats to save it in a datastore it gets 0 even if the value is not 0 Zrxiis 26 — 4y
Ad

Answer this question