The player presses Q to punch and i want to make it so when you kill a npc you get more strength. For the 1st npc i want it to give you 10k strength per kill.
This is the script i have inside the npc, its not adding the strength when the npc dies. Theres no errors in output either.
I've tried making it so when the npc dies instead of the reward being 10k strength i put print "success" just to see if anything printed but it didn't so I'm thinking maybe the game isn't detecting that the npc died so I'm not getting the reward? I have no idea
local Humanoid = script.Parent;
local AmountToGive = 10000
Humanoid.Died:Connect(function()
local tagValue = Humanoid:FindFirstChild("creator").Value
if tagValue then
local leaderstats = tagValue:FindFirstChild("leaderstats")
leaderstats.strength.Value += AmountToGive
wait(0.1)
end
script:Destroy()
end)

2 comments
i got the error - Script timeout: exhausted allowed execution time
Probably due to the fact I'm using while true do. Just get rid of while true do and have it detect when the health is changed and when it hits 0 or lower then 0. You can find on google how to detect when a humanoid's Health changes.