Hi, I'm trying to make it save 2 IntValues in leaderstats. I've gotten it to save points, but not gems. What am I doing wrong? Thanks
local DSService = game:GetService("DataStoreService"):GetDataStore("SaveStats") game.Players.PlayerAdded:connect(function(player) -- Define variables local uniquekey = "id-"..player.userId local leaderstats = Instance.new("IntValue", player) local points = Instance.new("IntValue") local gems = Instance.new("IntValue") leaderstats.Name = "leaderstats" points.Parent = leaderstats points.Name = "Points" gems.Parent = leaderstats gems.Name = "Gems" -- GetAsync local GetSaved = DSService:GetAsync(uniquekey) if GetSaved then points.Value = GetSaved[1] gems.Value = GetSaved[2] else DSService:SetAsync(uniquekey, points.Value, gems.Value) end end) game.Players.PlayerRemoving:connect(function(player) local uniquekey = "id-"..player.userId local pointtable = {player.leaderstats.Points.Value} local gemtable = {player.leaderstats.Gems.Value} DSService:SetAsync(uniquekey, pointtable, gemtable) end)
I believe SetAsync only takes 2 arguments. The key, and the data. The gems will not save because that argument is unused and ignored by the function. I would use a table instead, eg { Points: points, Gems: gems }
then you can access it using GetSaved.Points
or GetSaved.Gems
.
You spelt UserId wrong lmao
also i dont think you do these in a table and im not sure u do "id-" before the userid.
local uniquekey = player.UserId local pointtable = player.leaderstats.Points.Value local gemtable = player.leaderstats.Gems.Value DSService:SetAsync(uniquekey, pointtable, gemtable)