Ad
Log in to vote
1

Why is this debounce nonfunctional?

Asked by 7 years ago

In this kill script that sucks that remaining parts of the player's character into the center of a part named "orb," the debounce acts as if it weren't there; it inserts the BodyPosition into each body part numerous times. Does anyone know how to make a working debounce for this function?

orb = script.Parent
Debounce = false

orb.Touched:connect(function(toucher) if Debounce == false then Debounce = true else return end --[[debounce wrap]]

    human = toucher.Parent:FindFirstChild("Humanoid")

    if human ~= nil then character = toucher.Parent else return end

    character:BreakJoints()

    for i, v in pairs(character:GetChildren()) do

        if v.ClassName == "Part" then

            v.CanCollide = false

            suction = Instance.new("BodyPosition")
                suction.Parent = v
                suction.D = 100
                suction.maxForce = Vector3.new(400000, 400000, 400000)
                suction.P = 1000
                suction.position = orb.Position

        end

    end

Debounce = false --[[end of debounce wrap]] end)

2 answers

Log in to vote
1
Answered by
adark 5467 Badge of Merit Moderation Voter Community Moderator
7 years ago

If you look at your code, there are no wait()s anywhere.

In order for debounce to work, you have to wait() before you reenable the code, otherwise it'll seem like it isn't even there.

What your code currently does is make the function run sequentially, instead of all at once.

Ad
Log in to vote
-1
Answered by 7 years ago

Also, make sure when you get out of the function, Debounce is set to false.

1
That is already in his code. User#11893 186 — 7y

Answer this question