Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Prints twice even with debounce?

Asked by 4 years ago

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)
0
Its an explosion part btw. When i touch a part my character explodes. legendcruncher82 -8 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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") 
Ad

Answer this question