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

Help with Coroutines?

Asked by 10 years ago

I was trying to make button that stops the weird flickering of the Transparency when a Character touches it with Touched event,but it didn't work out because the Coroutine doesn't start or resume,why? And is there another way to stop the weird flickering of the Transparency? If so please tell me.

local Part = script.Parent
-----------------------------
    ChangeTransparency = coroutine.create(function()--Checks if Transparency is 0.5 if it is then turn it to 0
        if Part.Transparency == 0.5
            then
            Part.Transparency = 0
        end
    end)
    -----------------------------
    coroutine.resume(ChangeTransparency)--Changes the part back to normal just incase it hasn't
        Part.Touched:connect(function(TouchedPart)    
            Part.Transparency = 0.5
            print("I've been touched")
            coroutine.yield(ChangeTransparency)--Stops coroutine
            end)
            -----------------------------
                Part.TouchEnded:connect(function()
                    coroutine.resume(ChangeTransparency)--Changes the part back to normal
                end)


1
Within the ChangeTransparency function, you'll need to re-define the variables as Lua is basically running it as its own script. An idea for the weird flickering is to use debounce. http://wiki.roblox.com/index.php?title=Debounce#Real_world Shawnyg 4330 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

Try using debounce;

local Part = script.Parent
local Debounce = false

Part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")and not Debounce then
Debounce = true
while Debounce == true do
wait(0)
Part.Transparency = 0.5
if Debounce == false then
break
end
end
end
end)

Part.TouchEnded:connect(function()
Debounce = false
Part.Transparency = 0
end)

A bit buggy, but it works. Hope this helped!

1
Properly tab your code. BlueTaslem 18071 — 10y
Ad

Answer this question