hello I have problems with my code. I use the Leaderstats code and it doesn’t work
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("StatsStore")
local Players =game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local data= store:GetAsync(Player.UserId)
local stats = Instance.new('Folder')
stats.Name = 'leaderstats'
stats.Parent = Player
local cash = Instance.new('IntValue')
cash.Name = 'Cash'
cash.Parent = stats
cash.Value = data['Cash'] or 10
local candy = Instance.new('IntValue')
candy.Name = 'Candy'
candy.Value = data['CandyA']
candy.Parent = stats
local multiplier = Instance.new('IntValue')
multiplier.Name = 'Multiplier'
multiplier.Value = 1
multiplier.Parent = Player
local speed = Instance.new('IntValue')
speed.Name = 'Speed'
speed.Value = 1
speed.Parent = Player
local function change()
local t = {
['Cash'] = Player:WaitForChild('leaderstats'):WaitForChild("Cash").Value,
['CandyA'] = Player:WaitForChild('leaderstats'):WaitForChild("Candy").Value
}
store:SetAsync(Player.UserId,t)
end
candy.Changed:Connect(change)
cash.Changed:Connect(change)
end)
Players.PlayerRemoving:Connect(function(Player)
print('PlayerRemoving: ' .. Player.Name)
local t = {
['Cash'] = Player:WaitForChild('leaderstats'):WaitForChild("Cash").Value,
['CandyA'] = Player:WaitForChild('leaderstats'):WaitForChild("Candy").Value
}
print(t)
store:SetAsync(Player.UserId,t)
end
Why is the code not saved but takes the values?
what is she doing wrong with my code
(sorry if the grammar is bad, I use google translate)strong text