I am making a script, that every time the npc dies, the player gets +10 coins to their leader stats named "coins". I use the player added function but it only adds plus 10 once. then when the npc health value reaches 0 again, it doesn't add +10. Please help!
local health = script.Parent --script is in a health value of my npc
health.Changed:Connect(function() if health.Value <= 0 then local currentposition = script.Parent.Parent.HumanoidRootPart.CFrame health.Value = 10 script.Parent.Parent.HumanoidRootPart.CFrame = turtlerespawn.CFrame
--Utter confusion--
game.Players.PlayerAdded:Connect(function(plr)
local player = plr
print(player.Name)
print("Plus 10")
player.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 10
end)
wait(5)
script.Parent.Parent.HumanoidRootPart.CFrame = currentposition
end
----------------------------------------------------------------------------------------
end)

1 comment
the coded part is the part that i'm trying to find the local player in.