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

Prints twice even with debounce?

So even with a debounce on my explosion part script, i added a print statement to see how many times it explodes. When i run it and touch the part, it prints multiple times, even with the debounce. Any reasons?

local debounce = false
script.Parent.Anchored = true
script.Parent.Position = Vector3.new(3,0.5,3)

script.Parent.Touched:Connect(function(hit)
	if debounce == false and hit.Parent:FindFirstChild("HumanoidRootPart")
	then
		debounce = true
		local explosion = Instance.new("Explosion")
		script.Parent.BrickColor = BrickColor.new("Really red")
	explosion.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position
	explosion.Parent = hit.Parent:FindFirstChild("HumanoidRootPart")
	game.Workspace.Part.pow:Play()
	print("Explosion")
	end
	wait(10)
	debounce = false
	script.Parent.BrickColor = BrickColor.new("Medium stone grey")
end)

1 comment

0

Its an explosion part btw. When i touch a part my character explodes.

1 answer

I'm not entirely sure, but it could have an issue with the hit.Parent:FindFirstChild("HumanoidRootPart") condition. Sometimes a handle from a hat or something can mess this up. To make sure HumanoidRootPart is really there, try this:

hit:FindFirstAncestorOfClass("Model"):FindFirstChild("HumanoidRootPart") 

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