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

How to make a door swing open and return to the same position?

Asked by 7 years ago
Edited 7 years ago

I'm very new to scripting and i'm trying to figure out C frames and how they function with doors. I have a door that opens but when it closes it is slightly off. Each time it opens and closes the door moves slightly further off until eventually it is far askew. I have tried tinkering with the numbers to get it to move minimally. However, it is always atleast a bit off. Here is the first half of the script. The second half is the same numbers but the negative counterpart.

Edit This door is a stove door that reacts through clicking to open it. in case this changes anyones answers.

function onClicked()
if script.Parent.Value.Value == true then
script.Parent.Value.Value = false
wait(0)
script.Parent.smoke.ParticleEmitter.Enabled = true
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.22) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
0
It'll save you a lot of trouble later on if you want to change something if you make a for loop for every time you change the CFrame rather than calling CFrame a bunch of times. Phantom1996 45 — 7y
0
Yes ^ hiimgoodpack 2009 — 7y
0
I'm not sure how to loop. I'll try to look into it thanks for the heads up! I'm guessing this is to clean up my script not fix the positioning problem correct? launcelothandsome 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

At this occasions, i would prefer using ROBLOX's physics system instead of scripting it which might ruin what i wanted to happen.

If you want a clean opening-and closing of a door back to its normal position without any mistakes or misplaced parts use 'Joints'. ROBLOX has already provided tutorials regarding this question; I would leave a link here.

https://www.youtube.com/watch?v=NihGyByDd_4

0
Not quite what i'm looking for. Atleast the video you linked isn't. Maybe i should be a bit more clear. This door is a stove door. People will not walk through this door they will click it and it will open so springs and hinges will not work unless if there is a way to make them function with click detectors. launcelothandsome 0 — 7y
0
My mistakes. Forgive me. Tolstoii 15 — 7y
0
No worries at all thanks for trying to help :) launcelothandsome 0 — 7y
Ad

Answer this question