Thats a normal thing for some reason
Okay well, I just tried it, and I donât really see it saving it either in Roblox Studio? It still does the same thing it did before, and the print does come out saying it was successful
Make sure you also have the playerRemoving function in your script as well as the bindtoclose.
in here you still added userId which iâve already did here
try removing the userId ang just do it like
savedata:SetAsync("id_"..id
So like this?
savedata:SetAsync("id_"..id, {id.leaderstats.Coins.Value, id.leaderstats.Money.Value, id.leaderstats.Gems.Value, id.leaderstats["Eggs Opened"].Value, id.leaderstats["Snow Coins"].Value, id.leaderstats["Snow Cash"].Value}) -- change data to the value you want to save
yes, that is right again.
asdasdasd
It still seems to have the same outcome
wait what is this, whyâd you do id.leaderstats, it should be plr (or âvâ since itâs in a for loop) right? maybe itâs because of this, sorry i didnât see this earlier
donât put plr but instead use âvâ because thatâs what i named the player variable
Still seems to do it
local ds = game:GetService("DataStoreService"):GetDataStore("savedata")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Coins
local save2 = plr.leaderstats.Money
local save3 = plr.leaderstats.Gems
local save4 = plr.leaderstats["Eggs Opened"]
local save5 = plr.leaderstats["Snow Coins"]
local save6 = plr.leaderstats["Snow Cash"]
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
save3.Value = GetSaved[3]
save4.Value = GetSaved[4]
save5.Value = GetSaved[5]
save6.Value = GetSaved[6]
else
local NumberforSaving = {save1.Value, save2.Value, save3.Value, save4.Value, save5.Value, save6.Value}
ds:GetAsync(plrkey, NumberforSaving)
end
end)
local datastoreservice = game:GetService("DataStoreService")
local savedata = datastoreservice:GetDataStore("savedata") -- your data store ofc
game:BindToClose(function()
local players = game.Players
local s, errorms = pcall(function()
for _, v in pairs(players:GetChildren()) do
local id = v.UserId
savedata:SetAsync("id_"..id {v.leaderstats.Coins.Value, v.leaderstats.Money.Value, v.leaderstats.Gems.Value, v.leaderstats["Eggs Opened"].Value, v.leaderstats["Snow Coins"].Value, v.leaderstats["Snow Cash"].Value}) -- change data to the value you want to save
end
end)
if s then
print("success saving players data")
else
warn(errorms)
end
end)
can i see the playeradded script which loads the data?
What do you mean? That script does it
- List item
tessssss
oh yes, right im sorry. i wasnât reading i thought it was a separate script, lol.
No, youâre all good
asdasdasdasdasdasd
i noticed that the getasync is not in a pcall maybe try adding a pcall?
edit: also whereâs the player removing? bindtoclose only functions when a server is dying so other players data would not get saved
Where exactly do I put the pcall? And is this what you mean?
local s, e = pcall(function()
-- save
end)
if not s then
print(asdasdasdasdwasdwasd) -- prints the error
end
yes, right.
This text will be hidden
So where do I put the pcall?
Summary
adsdasdasdwasdwasdwasdwasdwasdwasdwasdwasdwasd
i edited the script and it should work now, i hope lol.
local ds = game:GetService("DataStoreService"):GetDataStore("savedata")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Coins
local save2 = plr.leaderstats.Money
local save3 = plr.leaderstats.Gems
local save4 = plr.leaderstats["Eggs Opened"]
local save5 = plr.leaderstats["Snow Coins"]
local save6 = plr.leaderstats["Snow Cash"]
local s, e = pcall(function()
ds:GetAsync(plr.UserId)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
save3.Value = GetSaved[3]
save4.Value = GetSaved[4]
save5.Value = GetSaved[5]
save6.Value = GetSaved[6]
else
local NumberforSaving = {save1.Value, save2.Value, save3.Value, save4.Value,
save5.Value, save6.Value}
ds:GetAsync(plrkey, NumberforSaving)
end
end)
if s then
print("succefully loading player data")
else
warn("could not load player's data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local s, e = pcall(function()
ds:SetAsync("id_"..player.UserId, {v.leaderstats.Coins.Value, v.leaderstats.Money.Value, v.leaderstats.Gems.Value, v.leaderstats["Eggs Opened"].Value, v.leaderstats["Snow Coins"].Value, v.leaderstats["Snow Cash"].Value})
end)
if not s then
warn("Could not save "..player.Name.."'s data!")
end
end)
game:BindToClose(function()
local players = game.Players
local s, errorms = pcall(function()
for _, v in pairs(players:GetChildren()) do
local id = v.UserId
ds:SetAsync("id_"..id, {v.leaderstats.Coins.Value, v.leaderstats.Money.Value, v.leaderstats.Gems.Value, v.leaderstats["Eggs Opened"].Value, v.leaderstats["Snow Coins"].Value, v.leaderstats["Snow Cash"].Value}) -- change data to the value you want to save
end
end)
if s then
print("success saving players data")
else
warn(errorms)
end
end)
edit: i did a typo, itâs fixed now