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

Why does this Rotation Script not work?

All I am trying to do is make a model move/spin. But when I do this it doesn't move together and splits apart. I am pretty sure there is a way to do this, but I do not know how.

local model = script.Parent

function Move()
	for _,part in pairs (model:GetChildren()) do
		if part.ClassName == "Part" then
			part.Rotation = part.Rotation + Vector3.new(1,0,0) 
		end
	end
end


while true do
	Move()
	wait(1) -- speed
end

1 answer

✓ Accepted answer

Yes, there is a way to do this. I have never used the Vector3 of Rotation. Although, because it's Vector3, the second the part starts to rotate and Collides with another object, the part will be moved upwards until that collision no longer exists.

  • So, how can we rotate the parts without the allowance of collision?

We use a CFrame instead of Vector3! Well, what is CFrame? CFrame or Coordinate Frame is what defines an objects location and it's rotation as well. CFrame allows us to place one part inside of another.

So, to do this we need to go to the part then it's CFrame ( part.CFrame ). Due to us wanting to Rotate the part, we'll use CFrame.Angles. This is the same thing as CFrame.fromEulerAnglesXYZ, just basically a shorter name. Now, here is what your script will look like:

local model = script.Parent

function Move()
    for _,part in pairs (model:GetChildren()) do
        if part.ClassName == "Part" then
            part.CFrame = part.CFrame * CFrame.Angles(1, 0, 0) -- Only change is here!
        end
    end
end

while true do
    Move()
    wait(1) -- speed
end

You may want to adjust the (1,0,0) to your liking. You can find more information about CFrame here

I would suggest removing where you'll make this script a function and switch out where function Move() is and place the while true do, don't forget the wait!

Accept and UpVote if I helped, Ask if you have any questions!

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