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

Why isn't this debounce working?

Asked by 10 years ago

I made a debounce that stops the Part from turning transparent if touched then once and then turn visible if it's done being touched,but it won't turn visible,why? Please show how you managed to fix it.

local Part = script.Parent
Touched = false
-----------------------------
    Part.Touched:connect(function(TouchedPart)
        Touched = true
        FoundHumanoid= TouchedPart.Parent:FindFirstChild("Humanoid")--Checks if it's a humanoid
        -----------------------------
                if not FoundHumanoid then
                    print("You're not a Character "..TouchedPart.Name.." !")
                else
                if not Touched then -- If not touched
                -----------------------------
                    Part.TouchEnded:connect(function(TouchEnd)--If the touch has ended then do the following
                    print("I haven't been touched!")
                        Part.Transparency = 0
                            Touched = false
                       end)
                    -----------------------------
                    else--If it's still touched then do the following
                         Part.Transparency = 0.5
                         print("I've been touched")
                        Touched = false

                      end 
                    end
                  end)

1 answer

Log in to vote
1
Answered by 10 years ago

I was here before but this should help ;)

local Part = script.Parent
Touched = false
-----------------------------
    Part.Touched:connect(function(TouchedPart)
        Touched = true
        FoundHumanoid= TouchedPart.Parent:FindFirstChild("Humanoid")--Checks if it's a humanoid
        -----------------------------
                if not FoundHumanoid then
                    print("You're not a Character "..TouchedPart.Name.." !")
                else
                -----------------------------
                         Part.Transparency = 0.5
                         print("I've been touched")
                        Touched = false

                    end
                  end)

                    Part.TouchEnded:connect(function(TouchEnd)--If the touch has ended then do the following
                    print("I haven't been touched!")
                        Part.Transparency = 0
                            Touched = false
                       end)
0
I know this is really messy coding, But I didn't attempt to make it look good as he should be able to understand hehe NovusTheory 133 — 10y
Ad

Answer this question