I'm trying to save 4 leaderstats in a DataStore using Tables. For some reason, only the first two leaderstats(Energy and Credits) are saving. I also have a problem where when a player joins the game the Speed leaderstat is going straight to zero. There are no errors and i have tried it in Studio and the actual game, and still the same problem. Could anybody help?
Heres the code
local DSS = game:GetService("DataStoreService")
local AllDS = DSS:GetDataStore("AllDataStore")
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local hidden = Instance.new("Folder")
hidden.Name = "hidden"
hidden.Parent = player
local Energy = Instance.new("IntValue")
Energy.Name = "Energy"
Energy.Value = 1
Energy.Parent = stats
local Credits = Instance.new("IntValue")
Credits.Name = "Credits"
Credits.Value = 1
Credits.Parent = stats
local Speed = Instance.new("IntValue")
Speed.Name = "Speed"
Speed.Parent = stats
Speed.Value = 8
local Jump = Instance.new("IntValue")
Jump.Name = "Jump"
Jump.Value = 70
Jump.Parent = hidden
local playerUserId = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = AllDS:GetAsync(playerUserId)
end)
if success then
Energy.Value = data.Energy
Credits.Value = data.Credit
Speed.Value = data.Speed
Jump.Value = data.Jump
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
Energy = player.leaderstats.Energy.Value;
Credits = player.leaderstats.Credits.Value;
Speed = player.leaderstats.Speed.Value;
Jump = player.hidden.Jump.Value;
}
local success, error,essage = pcall(function()
AllDS:SetAsync(playerUserId, data)
end)
if success then
print("Data was saved")
else
print("Did not save")
warn(errormessage)
end
end)

7 comments
What I'm saying is, change data.Credit to data.Credits.
Thanks, im trying now
If it works, please accept my answer :D
Sry Just came back
Alright, so you've helped me get the problem where the Speed was going to zero all the time fixed, but i still dont have the DataStore problem fixed, and i was just wondering where the RemoveAsync script would go? Thanks for the help
Use , instead of ; while saving data
Thanks dude it worked