Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this money/remove script only work half of the time?

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

2 comments

0

use spawn(function()

1

free model code lmao

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.