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

Help with door script?

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 comment

1

try using CFrame instead of position

1 answer

✓ Accepted answer
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

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