So I have created a balloon with a humanoid in it. The head is a balloon mesh and I shrunk all the other body parts inside the mesh. Below is 2 different scripts. The first one gives the player points if they pop the balloon and the other plays a pop sound and then removes the balloon all together. If I walk up to the balloon with a sword and pop it everything works great (Balloon gets popped and player receives points), but when I use a gun from a distance and kill the balloon it will delay about 4 seconds before popping and the player doesn't receive any points. Any idea on why this is happening?
StatName = "Points" IncreaseValue = 20 local Humanoid = script.Parent.Humanoid function PwntX_X() local tag = Humanoid:findFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats[StatName].Value = Leaderstats[StatName].Value + IncreaseValue wait(0.1) script:remove() end end end end Humanoid.Died:connect(PwntX_X) --- next script while true do wait(.01) if script.Parent.Humanoid.Health<1 then wait(.01) script.Parent.Sound:Play() script.Parent:remove() end end
Try this:
StatName = "Points" IncreaseValue = 20 local Humanoid = script.Parent.Humanoid function PwntX_X() local tag = Humanoid:findFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats[StatName].Value = Leaderstats[StatName].Value + IncreaseValue wait(0.1) script:Destroy() end end end end Humanoid.Died:connect(PwntX_X) spawn(function() while true do wait(.01) if script.Parent.Humanoid.Health<1 then wait(.01) script.Parent.Sound:Play() script.Parent:Destroy() end end end)
also I don't think creator tags work anymore lol oof. But anyways, if this helps, remember to accept answer.
Spawn(function() allows multiple loops to run. In your case, when your humanoid dies, nothing will happen because the loop is running.
If it doesn't work then reply in comments.