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

(SOLVED) Debounce stops code from running at all?

Asked by 4 years ago
Edited 4 years ago

I'm creating a little touch part to demonstrate a database system, the idea being every time you touch the part you get 5 points. Since the roblox touch system is a bit finnicky, I need a debounce which is pretty simple. My code is as follows;

local debounce = true
TestPart.Touched:Connect(function(Part)
if debounce == true then
        debounce = false
        print('ok')


    if Part.Parent:FindFirstChild('HumanoidRootPart') then

-- code is here

        end
        wait(5)
        debounce = true
    end
end)

When I touch this part the code doesn't run at all. Why is this happening and how can I solve it?

0
what type of script is this, and where is it located? megukoo 877 — 4y
0
Normal script in workspace VoidKeyword 111 — 4y
0
Is the script disabled? Did you specify a variable for the part in question? Rinpix 639 — 4y
0
can you add the variable TestPart in the question? BestCreativeBoy 1395 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

i use this code to test your code. And it works. Try to change the parameter to hit and btw i put this code inside the part

local TestPart = workspace.Part
local debounce = true
TestPart.Touched:Connect(function(hit)
        if debounce == true then
        debounce = false
        print('ok')
        if hit.Parent:FindFirstChild('HumanoidRootPart') then

            print("HumanoidPart")

        end
        wait(5)
        debounce = true
    end
end)
0
You don't have to change the parameter to hit, it doesn't matter. NotTheChara 191 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

It seems to me that your script is touching other non-humanoid parts so debounce is false at all times. Try only changing the debounce after a HumanoidRootPart is found.

Log in to vote
0
Answered by 4 years ago

Setting the part collision to off seemed to do the trick.

Answer this question