Can't get a mesh to rotate

Hey developers, I’ve been having some issues with this code:

local speed = 1


local RobuxsIcon =
	script.Parent:FindFirstChild("MeshPart")


if RobuxsIcon and 
	RobuxsIcon:IsA("MeshPart") then
	while true do
		RobuxsIcon.CFrame =
			RobuxsIcon.CFrame * CFrame.Angles(0, math.rad (speed), 0)
		wait(0.01)
	end
end
print("MeshPart not found or invalid.")

--- Coded by Joeys2Valid

I test the script but doesn’t move, I checked to see if the MeshPart name was correct and It was, any ideas?

2 Likes

My guess is that MeshPart is not loaded in time. Even thought the script is under the same parent as the MeshPart, it could be loading before it. Try using WaitForChild instead of FindFirstChild.

1 Like

Your code works fine. I just pasted it in and the MeshPart spun correctly. Are you setting the cframe anywhere else? Is the meshpart missing? Is the print you put at the end of the file appearing in the output?

1 Like

I tried to change it into WaitForChild but It’s still not working

I have the orientation set to 0,0,0 Mesh part isn’t missing, I still have seem to figure out what’s wrong.

If your script is a LocalScript, they don’t work when parented to objects inside of workspace. Inside of a server Script that’s a child of the MeshPart you want to rotate do:

local speed = 1

local RobuxsIcon = script.Parent

local RobuxIconCFrame = RobuxsIcon.CFrame

while true do
	RobuxsIcon.CFrame = RobuxIconCFrame * CFrame.Angles(0, math.rad(speed), 0)

	task.wait()
end

And if you’d like for the loop to run on the client, a convenient solution is to go to this server Script’s properties in the Explorer and change it’s RunContext from Legacy to Client. If the script is a direct child of the MeshPart, you won’t need to change the code I gave you :slight_smile::+1:

1 Like

Script was under a LocalScript, but still can’t make the mesh part move after changing it to a Script, I’ve changed it to client. But still no use.

If you take the MeshPart and script to a new baseplate, is the issue still present?

Yes, I took the MeshPart into a new baseplate with the script, Still isn’t spinning.

1 Like

I found the cause of the problem, we’re both forgetting to increment the speed value like so:

local speed = 1

local RobuxsIcon = script.Parent

local RobuxIconCFrame = RobuxsIcon.CFrame

while true do
	speed += 1

	RobuxsIcon.CFrame = RobuxIconCFrame * CFrame.Angles(0, math.rad(speed), 0)

	task.wait()
end

I literally didn’t even think about that, thank you so much I got it to work!

1 Like

I just looked back into the main game I’m trying to put it in but still isn’t working.

Remember to use a server Script with the RunContext set to Client, not a LocalScript since they don’t work inside workspace

1 Like

Check, and check, still not working…

Is the script a direct child of the MeshPart?

Yes the script is a direct child of the MeshPart.

This is quite strange since there doesn’t seem to be anything that would cause this problem, at this point if you can share the place file it would be very helpful to identify the cause

1 Like

If you have discord, I wouldn’t mind screensharing to you maybe then we could figure it out

(Joeys2Valid)

I don’t have a Discord account unfortunately

A screenshot of the explorer where you have your script would be helpful as well

Edit: @Joeys2Valid Another test you could try is to make sure you removed all scripts containing the old version of the code, else the loops will cancel each other out and the MeshPart won’t rotate

2 Likes

Meanwhile i wait for a Screenshot tool I’ll make sure I removed all the other scripts, Screenshot will be coming shortly.

Edit: @JohhnyLegoKing All scripts from before have been removed tested still didn’t work screenshot tool is almost done downloading as well.

1 Like