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

How can I stop my door from always going up?

In my game I have a huge door with a button you press, when you press it the door goes into the air, but doesn't stop. The way the door is set up is like this: workspace: Model: Button: ClickDetector, Script, ColorScript, MoveScript, Door: DoorScript

In the move script this is what I have wrote:

function myfunction()
local brick= script.Parent.Parent.Door
while wait(0) do 
for I=1,20 do 
brick.CFrame=brick.CFrame+Vector3.new(0,0.3,0)
wait() 
end
end
end

script.Parent.ClickDetector.MouseClick:connect(myfunction)

2 comments

0

Please can you put it into the code blocks so it's easier to read.

0

I'm like 99% sure your problem is that you are looping forever by doing "while wait(0) do". I would just do the for loop on it's own and that should work.

1 answer

✓ Accepted answer

If you only want this to run only when the button is clicked you don't need a while loop you can just have the for loop in your function . You'd also want a debounce so the button can't be spammed.

local debouce = false

local function myfunction() 
	if not debouce then
		debouce = true

		--// Door open loop
		local brick = script.Parent.Parent.Door  
		for i = 1, 20 do 
			brick.CFrame = brick.CFrame + Vector3.new(0,0.3,0) 
			wait() 
		end
		
		wait(2) --// How long until the button can be clicked
		debouce = false
	end
end	

script.Parent.ClickDetector.MouseClick:connect(myfunction)

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