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?
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.
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?
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
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
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
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