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

How come one of my IntValues aren't saving?

Asked by 6 years ago

Hi, I'm trying to make it save 2 IntValues in leaderstats. I've gotten it to save points, but not gems. What am I doing wrong? Thanks

local DSService = game:GetService("DataStoreService"):GetDataStore("SaveStats")
game.Players.PlayerAdded:connect(function(player)
    -- Define variables
    local uniquekey = "id-"..player.userId
    local leaderstats = Instance.new("IntValue", player)
    local points =  Instance.new("IntValue")
    local gems = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    points.Parent = leaderstats
    points.Name = "Points"
    gems.Parent = leaderstats
    gems.Name = "Gems"


    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        points.Value = GetSaved[1]
        gems.Value = GetSaved[2]
    else
        DSService:SetAsync(uniquekey, points.Value, gems.Value)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
local uniquekey = "id-"..player.userId
local pointtable = {player.leaderstats.Points.Value}
local gemtable = {player.leaderstats.Gems.Value}
DSService:SetAsync(uniquekey, pointtable, gemtable) 

end)
0
you can only save one value per SetAsync, so you either do SetAsync(UniqueKey,{Pointtable,Gemtable}), or you do two SetAsyncs. (I recommend the first one.) RubenKan 3615 — 6y

2 answers

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
6 years ago
Edited 6 years ago

I believe SetAsync only takes 2 arguments. The key, and the data. The gems will not save because that argument is unused and ignored by the function. I would use a table instead, eg { Points: points, Gems: gems } then you can access it using GetSaved.Points or GetSaved.Gems.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You spelt UserId wrong lmao

also i dont think you do these in a table and im not sure u do "id-" before the userid.

local uniquekey = player.UserId
local pointtable = player.leaderstats.Points.Value
local gemtable = player.leaderstats.Gems.Value
DSService:SetAsync(uniquekey, pointtable, gemtable) 

Answer this question