hello reader, im currently trying to use a shop model from toolbox for my game to buy tools etc. im having troubles with the leaderstats script though because the game just isnt loading the data, its required to load data to work but the data doesnt load heres the script anyone know whats wrong?
local ds = nil
game.Players.PlayerAdded:Connect(function(plr)
wait(0.05)
local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr
local Cash = Instance.new("IntValue") Cash.Name = "Cash" Cash.Value = 500 Cash.Parent = leaderstats
ds = game:GetService("DataStoreService"):GetDataStore("Game")
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Cash
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
else
local NumberForSaving = {
save1.Value
}
ds:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId, {
plr.leaderstats.Cash.Value
})
end)
local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local Ds = DSS:GetDataStore("Game2")
local function GetData(Player:Player, Saving:boolean, Info:any?)
local Tries = 0
local Max = 3
local Sucess, Data = nil
local ID = `{Player.UserId}`
repeat
Tries += 1
Sucess, Data = pcall(Saving and Ds.SetAsync or Ds.GetAsync, Ds, ID, Info)
if not Sucess and Data then warn(Data) end
task.wait(1)
until Sucess or Tries == Max
return Data
end
Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local PlayerData = GetData(Player, false, nil)
Cash.Value = PlayerData and PlayerData[1] or 0
end)
game.Players.PlayerRemoving:Connect(function(Player)
GetData(Player, true, {Player:FindFirstChild("leaderstats"):FindFirstChild("Cash").Value})
end)
The issue was primarily with this section:
The second GetAsync shouldn’t be included because you’re doing unnecessary requests and you’re passing the wrong data for the second parameter. The code I wrote is very basic but it should get the work done
so if you have had any scripting experience there’s that commit script to add it but if its not pushed and you have not added your what’s new description or if its in drafts you can press the third option on the play button is the test button to test recent scripts and gui and animation in stuff @dashypoo17