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)
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