Hello, a few weeks ago I watched a tutorial on DataSaving from AlvinBlox, mainly because I was a little confuzzled with it. I'm trying to save a number value (I believe it's called integers) via a location in the player's gui. Here's my code:
local DSService = game:GetService('DataStoreService'):GetDataStore('XIPHER_921838582315538283812581238529158283')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local savevalue = plr.PlayerGui:WaitForChild("Cash").CashFrame.MoneyHolder.Money.MoneyHolder
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.PlayerGui:WaitForChild("Cash").CashFrame.MoneyHolder.Money.MoneyHolder.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
As you can see, I'm trying to save a value in a place in the player's gui. The script is a normal script, not a localscript and is in ServerScriptStorage. If anyone can help me whether if it should be in a different location, if it should be a localscript instead, or generally help me. Super appreciated!
P.S I tried earlier with studio and it does load a integer I saved a few minutes ago when I used leaderstats instead and realized that it does load the saved data but it doesn't save the data. For example, if the player had saved 10k coins from earlier, and it correctly saved. The player joins back and earns another 10k coins and then leaves. It will only load in 10k coins because it doesn't save the coins and will only load the last data that WAS saved.

1 comment
Don't come on this site with alvinbloxx's code, expecting for it to be fixed.