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

Why does my part rotate like crazy?

For some reason my part rotates like crazy, rather than rotating calmly in the one direction it should.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if script.Parent.Value.Value == false then
		for i = 1,45 do
		script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X + 1),script.Parent.Orientation.Y,script.Parent.Orientation.Z)
		wait()
		end
	end
end)

2 answers

Hello, Jexpler!

This is because wait() is the same of wait(0.01) (I think) and this is a really fast time! Try adding a .05, this will make the moviment smother =3

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if script.Parent.Value.Value == false then
        for i = 1,45 do
        	script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X + 1),script.Parent.Orientation.Y,script.Parent.Orientation.Z)
        	wait(.05)
        end
    end
end)

Good Luck with your games

1 comment

0

I meant it's rotating on X, Y and Z

Change this monstrosity:

CFrame.new(script.Parent.Position) * CFrame.Angles(math.rad(script.Parent.Orientation.X + 1),script.Parent.Orientation.Y,script.Parent.Orientation.Z)

to

script.Parent.CFrame * CFrame.Angles(math.rad(1), 0, 0)

You want to keep the original CFrame, so use the original rather than creating a new one at the same position.

Multiplying CFrame.Angles() applies the rotation, it doesn't set the rotation. This means that if you give Angles() "Orientation.X" which is currently at 200 degrees, it will attempt to rotate the part 200 degrees, not set it to 200.

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