**My error: ** attempt to index local 'SavedData' (a number value)
Error is on line 15*
It's not saving data, most likely from the 1 error.
local PlayerData = game:GetService('DataStoreService'):GetDataStore('PlayerData')
game.Players.PlayerAdded:connect(function(Player)
local Stats = Instance.new('Folder', Player)
Stats.Name = 'Stats'
local Coins = Instance.new('IntValue', Stats)
Coins.Name = 'Coins'
--//DataStore
local Key = 'id-' ..Player.userId
local SavedData = PlayerData:GetAsync(Key)
if SavedData then
Coins.Value = SavedData[1]
else
local DataToSave = {Coins.Value}
PlayerData:SetAsync(Key, DataToSave)
end
Player.CharacterAdded:connect(function(Character)
Character:WaitForChild("Animate"):remove()
end)
end)
game.Players.PlayerRemoving:connect(function(Player)
local Key = 'id-' ..Player.userId
local SaveData = Player.Stats.Coins.Value
PlayerData:SetAsync(Key, SaveData)
end)

1 comment
I watched a youtube tutorial on how to make this DataStore but Idk why they put "SavedData[1]"