Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Transparency While Loop Help?

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

✓ Accepted answer

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.

1 comment

0

Thanks for this, but I was using this for a tycoon, and the buttons would slowly fade away.

This discussion is preserved as it was. New answers, comments, and votes are closed.