hi scripter, so, ive just made a auto save and leaderboard (on top of screen) But the save does not save... If you want to see it, here you go! https://www.roblox.com/games/722511272/Jumpy-racing-Under-construction But what am I doing wrong?
game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local Points = Instance.new ('IntValue', stats) Points.Name = 'Wins' end)
local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232') game.Players.PlayerAdded:connect(function(plr) -- Define variables local uniquekey = 'id-'..plr.userId local leaderstats = Instance.new('IntValue', plr) local savevalue = Instance.new('IntValue') leaderstats.Name = 'leaderstats' savevalue.Parent = leaderstats savevalue.Name = 'Wins' -- 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.leaderstats.Wins.Value} DSService:SetAsync(uniquekey, Savetable) end)
I hope you can help me out! thanks! good luck with other scripting!
-Gamer_io
Paste this in a normal script inside of "ServerScriptService"
GetService = game:GetService("DataStoreService") local Storage = GetService:GetDataStore("Hamburger223232") game.Players.PlayerAdded:connect(function(Player) --LEADERSTATS-- local User = Player.userId local UserKey = "User_"..User local SavedData = Storage:GetAsync(UserKey) local Stats = Instance.new("IntValue", Player) Stats.Name = "leaderstats" local Wins = Instance.new("IntValue", Stats) Wins.Name = "Wins" Wins.Value = 0 --DataStore-- if SavedData then Wins.Value = SavedData[1] else local NumbersNeeded = {Wins.Value} Storage:SetAsync(UserKey, NumbersNeeded) end end) game.Players.PlayerRemoving:connect(function(Player) local User = Player.userId local UserKey = "User_"..User local Savetable = {Player["leaderstats"].Wins.Value} Storage:SetAsync(UserKey, Savetable) end)
Already Tested it and it works great!