Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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)
0
How do you fix everything touching it being moved when you click the door Iamverychill2 4 — 3y
Ad
Log in to vote
-2
Answered by 10 years ago

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)

0
Ok I posted Loriese 0 — 10y

Answer this question