So, I was wondering if my DataStore will only save data if the player doesn't get their username changed. How can I fix this? I was wondering if I should acquire their user ID instead of their username but I'm not sure how to do this.
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Save") -- ??
local statstorage = player:FindFirstChild("PlayerStats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
end)
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Save") -- ??
player:WaitForChild("PlayerStats")
wait(1)
local stats = player:FindFirstChild("PlayerStats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numba "..i.." has been found")
end
end)
