So, everytime you die, I want the deaths value going up by 1. What did I do wrong here? I am a beginner so any help would be appreciated.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Deaths")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Deaths = Instance.new("StringValue")
Deaths.Name = "Deaths"
Deaths.Value = DataStore:GetAsync(player.UserId) or 0
Deaths.Parent = leaderstats
local character = player.character
character.Died:Connect(function() -- don't know what to do in this line
player.Deaths.Value = player.Deaths.Value + 1
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Deaths.Value)
end)
This would be the fix youâre looking for I think:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetDataStore("Deaths")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Deaths = Instance.new("StringValue")
Deaths.Name = "Deaths"
Deaths.Value = DataStore:GetAsync(player.UserId) or 0
Deaths.Parent = leaderstats
player.character.Humanoid.Died:Connect(function() -- don't know what to do in this line
leaderstats.Deaths.Value = leaderstats.Deaths.Value + 1
end)
end)
Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Deaths.Value)
end)
player.CharacterAdded:Connect(function(Character)
Character:WaitForChild("Humanoid").Died:Connect(function() -- don't know what to do in this line
leaderstats.Deaths.Value = leaderstats.Deaths.Value + 1
end)
end)