Hello Scripters! I have some trouble rotating a brick in a while true do or a for i form. I trie doing this script but it did not work. Please help
local p = game.Workspace.Part while true do p.CFrame = p.CFrame + p.CFrame * CFrame.Angles(math.rad(0),math.rad(10),math.rad(0)
You cannot use the '+' operator with with two CFrames check the CFrame operators.
More information about CFrame rotation can be found here.
Secondly since you only want to add rotation you add it to the existing CFrame e.g:-
p.CFrame = p.CFrame * CFrame.Angles(0, math.rad(10), 0)
Lastly you need to include some form of 'wait' in an infinite loop else it will allow other code to run causing studio / Roblox to crash in most cases.You have also missed the end
but this may just be an oversight.
Putting this code together:-
-- the part we are rotating local p = game.Workspace.Part while true do wait(0.2) -- force the script to wait p.CFrame = p.CFrame * CFrame.Angles(0, math.rad(10), 0) end -- a better solution would be to create the CFrame.Angles roblox data constructor and store it in a variable as it does not change local p = game.Workspace.Part local cf = CFrame.Angles(0, math.rad(10), 0) while true do wait(0.2) -- force the script to wait p.CFrame = p.CFrame * cf end
I hope this helps, please comment if you do not understand how / why this code works.