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

Datastore script only saving if intvalues are 0?

Asked by 4 years ago

So I have this script here

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("ds1")
local ds2 = datastore:GetDataStore("ds2")

game.Players.PlayerAdded:connect(function(plr)
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local fruits = Instance.new("IntValue", folder)
    fruits.Name = "Fruits"
    local coins = Instance.new("IntValue", folder)
    coins.Name = "Coins"

    fruits.Value = ds1:GetAsync(plr.UserId)
    ds1:SetAsync(plr.UserId, fruits.Value)

    coins.Value = ds2:GetAsync(plr.UserId)
    ds2:SetAsync(plr.UserId, coins.Value)

    if plr.leaderstats.Fruits.Value == 0 then
        warn("data not loaded")
    end
    if plr.leaderstats.Coins.Value == 0 then
        warn("data not loaded")
    end
end)
game.Players.PlayerRemoving:connect(function(plr)
    local fruits = plr.leaderstats.Fruits
    local coins = plr.leaderstats.Coins

    ds1:SetAsync(plr.UserId, fruits.Value)
    print("data saved")

    ds2:SetAsync(plr.UserId, coins.Value)
    print("data saved")

end)

Whenever I disconnect output gives a message about the datastore being quethed, however that only happens whenever the int values are zero. I tried changing them with a script and manually with explorer but I cannot get it to save.

0
I think the reason it saves only zero is cause the way the values are changing is if you do it with local scripts or in the explorer from the client side. I just tested it and it worked fine for me when I used a normal script to change the values deth836231 142 — 4y

Answer this question