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

Trouble with DataStoreService, a little help?

Asked by 5 years ago

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

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 User#7446 0 — 5y
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. greatneil80 2647 — 5y
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. SnowFunsize 55 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question