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

Data store script not showing credit beside character?

Asked by 8 years ago

Been working on it for abit now and I still can't seem to get the currency shown beside my character when I log into my game?

local DSservice = game:GetService("DataStoreService"):GetDataStore('Memes')
game.Players.PlayerAdded:connect(function(plr)
-- define variables
local uniquekey = 'id-' ..plr.userId
local leaderstats = Instance.new('IntValue',plr)
local saveValue = Instance.new('IntValue')
leaderstats.Name = 'Leaderstats'
saveValue.Parent = leaderstats
saveValue.Name = 'Cash'


-- GetAsync
local GetSaved = DSservice:GetAsync(uniquekey)
if GetSaved then
    saveValue.Value = GetSaved[1]
else
    local NumberForSaving = {saveValue.Value}
    DSservice:SetAsync(uniquekey,NumberForSaving)
end

end)

game.Players.PlayerRemoving:connect(function(plr)
    local uniquekey = 'id-'.. plr.userId
    local savetable = {plr.Leaderstats.Cash.Value}
    DSservice:SetAsync(uniquekey,savetable)

end)

Answer this question