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

How do I make the door open when I click it?

I have a door leading into a bedroom/cabin. When you click the door, it opens. Example: A door is in front of me. I want it to open. So I click it. When I click it, it slides open. Like a sliding door. Help?

This is what I think I need:

Click Detector

Script inside Click Detector

2 answers

Do this with CFrame, not Vector3, because when you use CFrame, your part can go through objects rather than colliding with them.

local click = script.Parent
local door = click.Parent
local closed = false
local db = true

local function control(start_pos,end_pos,inc)
	for i = start_pos, end_pos, inc do -- Start @, end @, go up or down by a number
		if end_pos < 0 then -- Asking if it's closed, so we can use the correct sign.
			door.CFrame = door.CFrame - Vector3.new(i,0,0)
		else
			door.CFrame = door.CFrame + Vector3.new(i,0,0)
		end
		wait()
	end
end

click.MouseClick:connect(function() 
	if db then
		db = false
		if not closed then -- open
			control(-5,0,1) -- -start, end, inc
			closed = true
		else -- close
			control(0,-5,-1)
			closed = false
		end
		db = true
	end
end)

1 comment

0

How do you fix everything touching it being moved when you click the door

01 local click = script.Parent 02 local door = click.Parent 03 local closed = false 04 local db = true 05

06 local function control(start_pos,end_pos,inc) 07 for i = start_pos, end_pos, inc do -- Start @, end @, go up or down by a number 08 if end_pos < 0 then -- Asking if it's closed, so we can use the correct sign. 09 door.CFrame = door.CFrame - Vector3.new(i,0,0) 10 else 11 door.CFrame = door.CFrame + Vector3.new(i,0,0) 12 end 13 wait() 14 end 15 end 16

17 click.MouseClick:connect(function() 18 if db then 19 db = false 20 if not closed then -- open 21 control(-5,0,1) -- -start, end, inc 22 closed = true 23 else -- close 24 control(0,-5,-1) 25 closed = false 26 end 27 db = true 28 end 29 end)

1 comment

0

Ok I posted

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