When the player first joins it works fine and gives the second tool and deletes the first but when the player dies it does not give the second tool and does not delete the first?
if Data2 then
if Data2 == 1 then
else
if Data2 == 2 then
for i, v in pairs (player.Backpack:GetChildren()) do
if table.find(canesChart.Canes, v.Name) then
v:Destroy()
end
end
local clone = game.ReplicatedStorage.Canes.MintCandyCane:Clone()
clone.Parent = player.Character
end
end
end
Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = player
local statstime = Instance.new("IntValue")
statstime.Name = "CandyCanes"
statstime.Parent = Stats
local statsCane = Instance.new("NumberValue")
statsCane.Name = "Cane"
statsCane.Parent = Stats
local Data = SaveDataStore:GetAsync(player.UserId)
local Data2 = CaneDataStore:GetAsync(player.UserId)
if Data then
for i,stats in pairs(Stats:GetChildren()) do
stats.Value = Data[stats.Name]
end
else
end
wait(1)
if Data2 then
if Data2 == 1 then
else
if Data2 == 2 then
for i, v in pairs (player.Backpack:GetChildren()) do
if table.find(canesChart.Canes, v.Name) then
v:Destroy()
end
end
local clone = game.ReplicatedStorage.Canes.MintCandyCane:Clone()
clone.Parent = player.Character
end
end
end
end)
It is only firing once, because a player is only added once.
When your character dies, or resets, it doesn’t fire the player added, it fires a character added
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character) --Check if player's Character is added
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = player
local statstime = Instance.new("IntValue")
statstime.Name = "CandyCanes"
statstime.Parent = Stats
local statsCane = Instance.new("NumberValue")
statsCane.Name = "Cane"
statsCane.Parent = Stats
local Data = SaveDataStore:GetAsync(player.UserId)
local Data2 = CaneDataStore:GetAsync(player.UserId)
if Data then
for i,stats in pairs(Stats:GetChildren()) do
stats.Value = Data[stats.Name]
end
else
end
wait(1)
if Data2 then
if Data2 == 1 then
else
if Data2 == 2 then
for i, v in pairs (player.Backpack:GetChildren()) do
if table.find(canesChart.Canes, v.Name) then
v:Destroy()
end
end
local clone = game.ReplicatedStorage.Canes.MintCandyCane:Clone()
clone.Parent = player.Character
end
end
end
end)
end)