I'm trying to script a door that becomes transparent

Recently, I’ve gotten back into figuring out Lua on Roblox, I’ve made a little bit of progress, however I’m aware that this fix is probably very easy, but I’m still a beginner with not much knowledge.

The idea is that there’s a door that when you click on a button, the door slowly starts to become transparent until it is fully open. I tried using a function for the click detection, and a for loop for the door transparency. However it doesn’t work and I tried a lot of things, even ditching the function and using an if else statement.

I do not request that you guys rescript this for me, I simply want to know the answer as to why this is happening. If you guys have any suggestions for how I can get better at Lua, please comment because I want to start taking this seriously. Thanks!

local door = game.Workspace.Model.Door.Transparency
par = script.Parent

function Clicked()
	for i = 0.25, 0, 4 do
		wait(1)
		door = i
	end
end

par.ClickDetector.MouseClick:connect(Clicked)

You need to set the variable as the Door object, not the transparency, because that will return you the value of transparency, not the property reference.

local door = workspace.Model.Door

Then in the for loop

door.Transparency = i
1 Like

I commonly use While loops for iterating things like these.

@ShutzCh is correct for one reason why your script isn’t working, but another reason may be your for loop.

2 Likes