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

Door Scripting Help?

So, I have been attempting to create a door that opens upon touching it, making it seem more authentic. Here's the code, the movement works, however every time the function is fired, the door teleports right above the house and continues the movement but in the wrong place.

local door = script.Parent.Part
function dooropening(plr)
	plr.Anchored = true
	for i = 1, 10 do 
	wait(0.1)
	door.CanCollide = false
	door.Anchored = true
	door.Position = door.Position + Vector3.new(0.1, 0, 0.1)
	door.Rotation = door.Rotation + Vector3.new(0, 10, 0)
	end
end

script.Parent.Part.Touched:connect(dooropening)

Any advice is much appreciated.

4 comments

0

For the position, try CFrame.

0

The above is the solution, I'm not sure why he didn't answer so I'll provide a demonstration along with his ^ answer.

0

I didn't see your answer, I have attempted CFrame but the Output states that CFrame produced an error and Vector 3 was expected

0

I was working on it xD It's finished now.

1 answer

✓ Accepted answer

You're using position, CFrame is much better, and will fix your problem.

Here's a link to the Roblox Wiki about CFrames.

Now, to make the position with a CFrame is very simple. All you have to do is put your code within a CFrame.new, and change your door.Position/Rotation to door.CFrame. Using CFrame can also shorten your code in a way. Here's what you would do,

local door = script.Parent.Part
function dooropening(plr)
    plr.Anchored = true
    for i = 1, 10 do 
    wait(0.1)
    door.CanCollide = false
    door.Anchored = true
    door.CFrame = CFrame.new(door.Position + Vector3.new(0.1, 0, 0.1)) * CFrame.Angles(0,math.rad(10),0)
    end
end

script.Parent.Part.Touched:connect(dooropening)

You can't add CFrames, you can only multiply. This is, in a way, much better in most circumstances.

CFrame.Angles is a easy way of rotating objects.

math.rad is a way of turning a number into angles. This is great for rotation.

I'm not 100% on CFrames, but I am sure that it's the answer to your problem.

Good Luck.

2 comments

0

I completely forgot about this, thank you for reminding me this will be a great help

0

<3

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