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

Transparency While Loop Help?

Asked by 10 years ago

So far, this is what I have, and I was wondering, How would I make a while loop that took the Transparency of b and every 0.2 seconds added 0.1 to b's Transparency after the brick is touched?

local b = script.Parent

function onTouch(part) 

end 

b.Touched:connect(onTouch)

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

So, first, imagine solving this problem without the context of Touched.

We would do exactly what you said:

while true do -- a while loop
    wait(0.2) -- every 0.2 seconds
    local bsTransparency = b.Transparency
    b.Transparency = bsTransparency + 0.1 -- 0.1 added to b's Transparency
end

Then we just can put this inside of our touched function:

local b = script.Parent

function onTouch(part) 
    while true do -- a while loop
        wait(0.2) -- every 0.2 seconds
        local bsTransparency = b.Transparency
        b.Transparency = bsTransparency + 0.1 -- 0.1 added to b's Transparency
    end
end 

b.Touched:connect(onTouch)

This will more or less work. Two ideas to improve it: add a debounce and reset the transparency to 0 each time it gets touched.

0
Thanks for this, but I was using this for a tycoon, and the buttons would slowly fade away. sketchy54 22 — 10y
Ad

Answer this question