Hi so basically, I'm trying to update a value on the player leaderstats when the player dies, but my script keeps returning this error: "ServerScriptService.PlrManager:13: attempt to index nil with 'FindFirstDescendant'". I know what this is, I just don't know what's causing it, because everything looks right.
Here is my code to help:
game.Players.PlayerAdded:Connect(function(Player)
local Container = Instance.new("Folder", Player)
Container.Name = "leaderstats"
local CurrentStage = Instance.new("IntValue", Container)
local Tokens = Instance.new("IntValue", Container)
local Deaths = Instance.new("IntValue", Container)
CurrentStage.Name = "Stage"
Tokens.Name = "Tokens"
Deaths.Name = "Deaths"
--below this is what's causing errors
local PIW = game.Workspace:FindFirstChild(Player.Name)
local Hum = PIW:FindFirstDescendant("Humanoid")
Hum.OnDied:Connect(function(onDeath)
Deaths.Value = Deaths.Value + 1
end)
end)

1 comment
You don't need to do FindFirstDescendant, because the Humanoid isn't a descendant of the player. Use FindFirstChild instead.