Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trouble with DataStoreService, a little help?

the text prints every time and the leader stats show, but it never saves.

local DS = game:GetService("DataStoreService"):GetDataStore("storage")

game.Players.PlayerAdded:Connect(function(plr)

local stats = Instance.new("Folder")

stats.Name = "leaderstats"

stats.Parent = plr

local Soul = Instance.new("IntValue")

Soul.Name = "Cash"

Soul.Parent = stats

Soul.Value = DS:GetAsync(plr.UserId) or 0

DS:SetAsync(plr.UserId,Soul.Value)

Soul.Changed:Connect(function()

print("saving")

DS:SetAsync(plr.UserId,Soul.Value)

print("finished saving")

end)

end)

game.Players.PlayerRemoving:Connect(function(plr)

print("saving data")

DS:SetAsync(plr.UserId,plr.leaderstats.Cash.Value)

print(plr.Name.."'s scream data has been saved")

end)

sorry about the code for some reason scripting helpers spaces it out when i paste it

3 comments

0

This happened to me, I solved it by using bind to close as well as player removing. It’s because every time u test it the place shuts down before the player removing can save it

0

in studio you are probably pressing the "stop" button, which will only work if you have BindToClose(), PlayerRemoving is when you press escape, L, and leave the game how it is suppose to be done.

0

Are you also sure that you have Studio Access to API Services enabled? I was able to paste this into a blank place and it worked fine for me. Are you also sure that when you edit the data it's done server side? If you try to alter it from the client it will not save information that's not present on the server.

1 answer

Did you check if your game has API services enabled. Also if this is in a team-create, those are kinda buggy.

This discussion is preserved as it was. New answers, comments, and votes are closed.