up = script.Parent.Up while true do script.Parent.CFrame = CFrame.new(script.Parent.Position.X, 13.5, script.Parent.Position.Z) script.Parent.Rotation = Vector3.new(0, 90, 0) up.Value = false wait(4) up.Value = true for i = 1, 12 do script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, .5, 0) wait() end wait(3) for i = 1, 12 do script.Parent.CFrame = script.Parent.CFrame - Vector3.new(0, .5, 0) wait() end end
This script makes a part go up and down, and after each loop, it resets the part to a certain point on the Y axis, while not affecting the other axes. When I tested the script, every time it reset positions, it would also reset the rotation to (0, 0, 0). I want it facing a certain way, so I added a line of code that changes the rotation after each loop. However, after each loop, the part rotates correctly but fails to reset to 13.5 (it resets to 20 instead). My best guess is that the part collides with a brick at the area it is supposed to reset to, so it resets to an area that doesn't collide with any bricks. Any way to fix it that doesn't involve getting rid of any collisions?
EDIT: Testing reveals that the brick collision is the source of the problem. I can't find a solution, however.
Change the rotation with a CFrame. Also, if you were to remove the Rotation line, it would prevent it from going to 20. CFrames always go where you want them to, unlike Vector3s, which move in case of collisions.
script.Parent.CFrame = CFrame.new(script.Parent.Position.X, 13.5, script.Parent.Position.Z) * CFrame.Angles(0,math.pi/2,0) -- math.pi/2 = 90 degrees
The code should all be one line.