If I have a value of 100 in my PlayerStats and I leave the game and a totally new player that's never played the game before joins they will also have a value of 100 in their PlayerStats. This happens with all vlaues saved in the DataStore. I'm new at creating DataStores can someone tell me what I'm doing wrong?
DataStore:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Stats")
game.Players.PlayerRemoving:connect(function(Player)
Player:WaitForDataReady()
local Stats = Player:FindFirstChild("PlayerStats"):GetChildren()
for i = 1, #Stats do
DataStore:SetAsync(Stats[i].Name,Stats[i].Value)
end
end)
game.Players.PlayerAdded:connect(function(Player)
Player:WaitForDataReady()
local Stats2 = Player:FindFirstChild("PlayerStats"):GetChildren()
for i = 1, #Stats2 do
Stats2[i].Value = DataStore:GetAsync(Stats2[i].Name)
end
end)
What the DataStore saves:
local Stats = {"Kills", "zCoins", "Points"}
local function Create(User)
local StatsFolder = Instance.new("Folder",User)
StatsFolder.Name = "PlayerStats"
for i = 1,#Stats do
Instance.new("IntValue",StatsFolder).Name = Stats[i]
end
end
game.Players.PlayerAdded:connect(function(Player)
Create(Player)
end)
