#data not saving ;-;

28 messages · Page 1 of 1 (latest)

brazen falcon
#

just a simple script of data save i found from dev forum and it isn't working, i haven't fully learned about data saving yet anything wrong? it prints out that it saved successfully tho```lua
local dts = game:GetService("DataStoreService")
local ds = dts:GetDataStore("mydatastore")

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue")
coins.Parent = leaderstats
coins.Name = "Coins"
coins.Value = 0

local playerid = "Player_"..plr.UserId
local data = ds:GetAsync(playerid)

if data then
    coins.Value = data['Coins']
else
    coins.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
local saving = {
Coins = plr.leaderstats.Coins.Value
}

local playerid = "Player_"..plr.UserId
local success, err = pcall(function()
    ds:GetAsync(playerid, saving)
end)

if success then
    print("Saved!")
else
    print("failed to save")
end

end)```

#

or it just doesn't work on studio?

gritty pollen
#

Try this much simpler script:
`
local dts = game:GetService("DataStoreService")
local ds = dts:GetDataStore("mydatastore")

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue")
coins.Parent = leaderstats
coins.Name = "Coins"
coins.Value = ds:GetAsync(coins.Value,plr.UserId) or 0

end)

game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(coins.Value,plr.UserId)
end)`

brazen falcon
#

so much errors

#

the coins suddenly saved to 3.2B

#

;-;

storm mortar
brazen falcon
storm mortar
#

Well I don't see anything in the code above that could multiply it to 3.2B

brazen falcon
#

the players id number may set the coins value tho

#

prob becuz of this coins.Value = ds:GetAsync(coins.Value,plr.UserId) or 0

storm mortar
#

Syntax
:SetAsync(value to save, player to save to)

Code above:
ds:SetAsync(coins.Value, plr.UserId)

storm mortar
brazen falcon
#

dunno i just coppied from dev forum

storm mortar
#

try swap the userId with the value (the places which they're in)

storm mortar
#

SetAsync is clearly being used in PlayerRemoving

brazen falcon
#

ur so formal bro

storm mortar
#

I'm just so based

#

My most sincerest apologies on my part

brazen falcon
#

weird if its a different game it works with this tho.. is it studio bug?```lua
local datastoreservice = game:GetService("DataStoreService")
local mystore = datastoreservice:GetDataStore("mydatastore")

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
coins.Value = 0

local money = Instance.new("IntValue",leaderstats)
money.Name = "Money"
money.Value = 0


local playerid = "Player_" .. player.UserId
local data = mystore:GetAsync(playerid)

if data then
    coins.Value = data['Coins']
    money.Value = data['Money']
else
    coins.Value = 0
    money.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local datatobesaved = {
Coins = player.leaderstats.Coins.Value;
Money = player.leaderstats.Money.Value;

}
local playerid = "Player_" .. player.UserId
local success, err = pcall(function()
    mystore:SetAsync(playerid,datatobesaved)
end)
if success then
    print("data saved!")
else
    print("data failed to save!")
end

end)```

storm mortar
#

Well at the end you put SetAsync which is setting data

trail cradleBOT
#

studio** You are now Level 7! **studio

storm mortar
#

and the first example was using GetAsync which gets data

brazen falcon
#

i see

storm mortar
#

So it was just a matter of changing from GetAsync to SetAsync on PlayerRemoving

brazen falcon
#

hmm i tested, same results

brazen falcon