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

Why does my fading door debounce not work?

I'm trying to make it so my simple fading door script doesn't freak out when I try to make it fade away while its fading back in.

cd = script.Parent.ClickDetector
dr = workspace.DoorR
dl = workspace.DoorL
dl2 = workspace.DoorL2
dr2 = workspace.DoorR2
dl3 = workspace.DoorL3
dr3 = workspace.DoorR3

local fading = false

cd.MouseClick:Connect(function()
	dr.CanCollide = false
	dl.CanCollide = false
	dr2.CanCollide = false
	dl2.CanCollide = false
	dr3.CanCollide = false
	dl3.CanCollide = false
	

	
	if fading == false then
		fading = true
		for i = 1,20 do
			dr.Transparency = dr.Transparency + 0.05
			dl.Transparency = dr.Transparency + 0.05
			dr2.Transparency = dr.Transparency + 0.05
			dl2.Transparency = dr.Transparency + 0.05
			dr3.Transparency = dr.Transparency + 0.05
			dl3.Transparency = dr.Transparency + 0.05
			wait(0.05)
		end
	end
	fading = false
	
	wait(10)
	
	if fading == false then
		fading = true
		for i = 1,20 do
			dr.Transparency = dr.Transparency - 0.05
			dl.Transparency = dr.Transparency - 0.05
			dr2.Transparency = dr.Transparency - 0.01
			dl2.Transparency = dr.Transparency - 0.01
			dr3.Transparency = dr.Transparency - 0.01
			dl3.Transparency = dr.Transparency - 0.01
			wait(0.05)
		end
	end
	
	fading = false
	
	dr.CanCollide = true
	dl.CanCollide = true
	dr2.CanCollide = true
	dl2.CanCollide = true
	dr3.CanCollide = true
	dl3.CanCollide = true
end)

I know there is a better way to do this script with in pairs but I couldn't be bothered. Any help would be greatly appreciated!

3 comments

0

this is a bad script damn

0

yeah, its wack

0

been scripting since 2015 and since I've taken numerous breaks from roblox that span months, I always take a step forward and take a step back

1 answer

✓ Accepted answer

You have the right idea on using debounce, but you never made an if statement for when the fading == true! That's all you're missing. Just add if fading then return end after line 10 and you should be all good. Please try to use a for loop next time.

3 comments

0

Thanks! So I assume that it prevents you from opening it again by telling the script that an arbitrary thing has ended?

0

Like I understand it in my head just not in words, I think

0

return basically stops the current scope (function if you will), and prevents anything from running after it. You can also choose to return a value with it, but it's not needed in this case. I didn't need == true since the default comparison for if statement is for true.

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