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

Help with door script?

Asked by
Scootakip 299 Moderation Voter
8 years ago
opened = false

script.Parent.ClickDetector.MouseClick:connect(function(oc)
    if opened == false then
script.Parent.Rotation = Vector3.new(0,90,0)
script.Parent.Position = script.Parent.Position + Vector3.new(1.5,0,0)
opened = true
    elseif opened == true then
script.Parent.Rotation = Vector3.new(0,0,0)
script.Parent.Position = script.Parent.Position + Vector3.new(-1.5,0,0)
opened = false
    end
end)

This is a door that I'm want to open and close on click. It's not animated, it's just a static close/open. The issue is that for some reason if someone is touching the door while it opens or closes, the door spawns above the person for some reason. Why is it doing this? Please help.

1
try using CFrame instead of position alex_ander 163 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
opened = false 
script.Parent.ClickDetector.MouseClick:connect(function(oc)
    if opened == false then 
    script.Parent.CFrame = CFrame.new(script.Parent.Position + Vector3.new(1.5,0,0)) * CFrame.fromEulerAnglesXYZ(0,math.rad(90),0)
    opened = true 
elseif opened == true then 
    script.Parent.CFrame = CFrame.new(script.Parent.Position - Vector3.new(1.5,0,0)) * CFrame.fromEulerAnglesXYZ(0,0,0)
    opened = false  
    end 
end) 

Use the CFrame value when the possibility of your brick attempting to move through another exists. If you were to use the Position value in such a situation, your part would shift above the object that it attempted to move through.

Illustration: https://gyazo.com/45eba853b1932fc4013b9930710ad2d1

Ad

Answer this question