How do I rotate an entire model?

So I’m trying make sword model rotate, I’ve set primarypart and cframe but this happens:

https://gyazo.com/624b8d1c0fd1df3347b50859fd5a093e

But this is what I want to happen:

https://gyazo.com/abf8a403f57951f1f015a3a2dc9f6b8e

Its broken and I don’t know why, here is the script

I tried rotating each part at a time but came out with this:

https://gyazo.com/d6c05e099eb84e95e4fff01b92c752d9

Here is the script,

script.Parent.PrimaryPart = script.Parent.H

script.Parent:SetPrimaryPartCFrame(script.Parent.H.CFrame)

while wait(0.081) do

for i,v in pairs(script.Parent:GetChildren()) do

if v:IsA("Part") or v:IsA("MeshPart") and v.Name == "H" then

v.Orientation = v.Orientation + Vector3.new(0,1,0)

print("rot")

end

end

end
1 Like

Here’s a tip:

Instead of using Orientation try using CFrame.Angles when using SetPrimaryPartCFrame()

2 Likes

If the reply above does not work ( which it probably will, however I am away from my laptop ), try Welding all the parts to your primary part and rotating the PrimaryPart from there.

I already tried that, but the result was that same.

I see. My apologies.

It’s possible you could try tweening the model. Here’s a good tutorial on it:
Introduction to Tweening Models

I’m not very great with CFrame.Angles but here is what I got,

local angleOffset = (script.Parent.H.CFrame * CFrame.Angles(0,math.rad(script.Parent.H.Orientation.X + 2),0))
   script.Parent:SetPrimaryPartCFrame(script.Parent.H.CFrame * angleOffset )

It glitches all over the maps constantly teleporting

Take that part out on angleOffset since it will multiply the CFrame by itself, which causes it go haywire.

I think the people here don’t know what they’re talking about. Your issue is likely in the if statement; you can just check if something is a BasePart instead, and using or and and in the same line without parentheses will cause you to mess something up.

Your fix is probably what @DevHumor suggested

Something like:

speed=math.rad(1)*40
while wait(.081) do
    currentCFrame=script.Parent:GetPrimaryPartCFrame()
    script.Parent:SetPrimaryPartCFrame(currentCFrame * CFrame.Angles(0, speed, 0))
end

Where you went wrong earlier was setting the angle offset; if you want a constant velocity rotation then the angle offset should be constant. Before you calculated the angle offset as a full CFrame (with position); which made it go haywire when you multiplied that CFrame position and rotation with the original.

3 Likes

Tysm, one problem though. For the most part it works but once it starts it randomly stops

https://gyazo.com/1a6b5b30dd8ddf86a3d15094616af8d3
I removed the script.Parent.H.CFrame part

Hmn, this is something I have not seen before.

Mind if I check out the edited script to see what I can find? It does seem to print it out, but somehow the CFrame didn’t get through.

Yes of course (Sorry for the late reply, I went for a run outside)

script.Parent.PrimaryPart = script.Parent.H
while wait(0.02) do
	for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Part") or v:IsA("MeshPart") and v.Name == "H" then
			local angleOffset = ( CFrame.Angles(math.rad(script.Parent.H.Orientation.X + 0.2),0,math.rad(0.0001)))
   script.Parent:SetPrimaryPartCFrame(script.Parent.H.CFrame * angleOffset )

		print("rot")
	end
end
end
	end
end
end

I really do not suggest using a very small number because it will make it look like it’s moving very slow despite having a loop run every 0.02 seconds.

Bump it up to 1 or higher if you can.

As for the stopping thing, I couldn’t seem to find any issues that’s causing it. :thinking:

Its okay, I have figured out the issue. Its due to the ‘H’ moving to a different orientation while not doing so at the same time. I bumped 0.2 to 10 and it works like a charm, its not changing the orientation 100% of the way but instead making it seem like it is. Basically what I’m saying is that it sets it to a position instead of always adding a position.

https://gyazo.com/af5a549c9058f7376afe1eeb3e9186b9

script.Parent.PrimaryPart = script.Parent.H
while wait(0.02) do
	for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Part") or v:IsA("MeshPart") and v.Name == "H" then
			local angleOffset = ( CFrame.Angles(math.rad(script.Parent.H.Orientation.X + 10),0,0))
   script.Parent:SetPrimaryPartCFrame(script.Parent.H.CFrame * angleOffset )


		print("rot")
	end
end
end

I really appreciate your help, thank you very much :smiley:

1 Like

https://gyazo.com/e53f43ba983108c0ab93f56b9741c4e1

You can see the orientation going up then resetting back to the bottom, I tried cropping the video but gyazo sadly can’t do that.

1 Like