I’m trying to make a button that once click, a door will fade open then fade closed after three seconds, my script doesn’t work, I also think that this is a lot of code for doing fading, is there a warparound?
For context the name of the door is “Door2”.
have you closed the function correctly? it says end end
The other end closes the if statement.
You gotta use for loops my dude, they’re amazing
function OnClicked() if Debounce == false then Debounce = true for i = 0, 1, .1 do wait(.1) Door.Transparency = i if i == .5 then Door.CanCollide = false end end for i = 1, 0, .-1 do wait(.1) Door.Transparency = i if i == .5 then Door.CanCollide = true end end Debounce = false end end
Is there any error in the console? Or does nothing happen when you click?
@Felixlous Even better implementation would be to use Tweens as they allow for a much smoother transition.
But aside from the fact that the many “Door.Transparency” statements is bad practice, I don’t see any issues with the code so it should work. As Physicism said, are you getting any errors? Are there maybe duplicate doors named “Door2” as that would break it.
Workspace.Button1.Script:11: attempt to index number with ‘CanCollide’
Means it isn’t pointing to the door, check the path again.
This is the path I’m referring to …
local Door = game.Workspace.Door2
That’s kinda strange though. If Door did not refer to an object, the script should error once it attempts to change its Transparency, not on CanCollide, right?
That is correct.
@Felixlous Are there any other errors? I’d still double check the path as that’s the most likely reason why it isn’t working.
I reference the game then workspace then Door2 (There’s only one Door2) then Door2’s transparency.
I figured it out, thank you guys for helping.