Part of code being skipped

Hi developers,

I have made a system that will allow the player to control their room with the simple click of a button on a GUI. However, I have an issue where you need to click twice for the script to register part of the code, here is the script,

local Door = script.Parent.Value.Value.Door.Door.Main.ProximityPrompt

locked = false

blinds = false
local DoorStat = Door.Value

local blindsmotor = script.Parent.Value.Value.Blinds.A.Motor

script.Parent.Gradient.Privacy.MouseButton1Click:Connect(function()
	if DoorStat.Value == false then -- If door is closed 
		if locked == false then -- if door is locked
			if blinds == false then -- if blinds are down
				
				Door.Enabled = false -- Disables Door
				locked = true -- Sets locked to true
				blinds = true -- sets blinds to true
				for i=1,100 do
					blindsmotor.C1 = blindsmotor.C1 + Vector3.new(0,-0.135,0) -- Pulls blinds up
					wait(0.0001)
				end -- end of putting the blinds up
				script.Parent.Gradient.EPB.Text = "Disable Privacy Blinds" -- sets text of button to disable privacy blinds
			else -- if blinds are up
				for i=1,100 do
					blindsmotor.C1 = blindsmotor.C1 + Vector3.new(0,0.135,0) -- Pulls blinds down
					wait(0.0001)
				end -- end of putting the blinds down
				Door.Enabled = true -- Enables Door
				locked = false -- Sets locked to false
				blinds = false	-- Sets blinds to false
				script.Parent.Gradient.EPB.Text = "Enable Privacy Blinds"
			end
		end		
	else
		script.Parent.Gradient.Warning:TweenSize(UDim2.new(1,0,0.193,0))
		wait(7)
		script.Parent.Gradient.Warning:TweenSize(UDim2.new(0,0,0,0))
	end
end)

Here is the line when you disables the blinds, that just gets skipped;

				for i=1,100 do
					blindsmotor.C1 = blindsmotor.C1 + Vector3.new(0,0.135,0) -- Pulls blinds down
					wait(0.0001)
				end -- end of putting the blinds down

It makes no sense why it doesnt work with the first click as everything after that does.

Any reason why you are looping and changing the position of a Motor6D and not just tweening the blinds model? Are the blinds supposed to be a humanoid with an animation?

In the end part, they just move down, and I’ve done this method several times each time I haven’t had any issues + Its the way i’ve always learnt how to animate objects.

Also, they work when it brings the blinds up, just not when the blinds move down.

This isn’t the best way to animate a static object. I don’t have a solution to your original problem, but I definitely have a suggestion. You should use TweenService for this process and drop the whole Motor6D business. Though you can’t tween models directly using TweenService, there is a neat “hack” for it. For more information, check this post:

Alright, I will look into it and see if i get any better results!

The wait value is too small. But even with that, it should just default to wait(), but maybe try it?