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)
This is kinda inefficient but could work.
local Humanoid = script.Parent; local AmountToGive = 10000 while true do if Humanoid.Health == 0 or Humanoid.Health < 1 or Humanoid.Health < 0 then local tagValue = Humanoid:FindFirstChild("creator").Value if tagValue ~= nil then local leaderstats = tagValue:FindFirstChild("leaderstats") leaderstats.strength.Value += AmountToGive wait(0.1) end script:Destroy() wait() end end
If this doesn't work it's probably because the "tagValue" you're looking for is nil and you'll need to create a value or find a way the player did damage to the NPC.