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
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)
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)