1

# How to make humanoid spin in a complete circle?

Hello, This sounds like a relatively easy thing to do, yet I've somehow managed to waste quite a bit of time trying to make the humanoid spin in a complete circle.

What am I doing wrong here? I know its that second half from this line that needs to be rotating the humanoid, but it instead turns the player towards a direction.

CFrame.new(character.PrimaryPart.Position) * CFrame.Angles(0,math.rad(360),0)


Thanks!

2

It's because you rotated the character directly at 360 degrees. To spin, you need to gradually increase the rotation until it reaches 360. You can achieve that using a for loop.

In case if you don't know what a for loop does, it has two types: for number = start, finish, increment do and for ... in function do.

The first one simply adds increment to number from start until number is equal to finish.

for number = 1, 10 do -- if increment is not set, it is automatically set to 1 as the default
print(number) -- prints 1 up to 10
end

for odd = 1, 9, 2 do
print(odd) -- prints all odd numbers from 1 to 9 (1, 3, 5, 7, 9)
end

for even = 2, 10, 2 do
print(even) -- prints all even numbers from 2 to 10 (2, 4, 6, 8, 10)
end


The second one is mostly used for tables. It gets the returned values from the function.

function test()
return "hi", "hello", "Roblox"
end

for a, b, c, d in test do
print(a, b, c, d) -- hi hello Roblox nil
-- the fourth prints nil because a fourth value wasn't returned by the function
end


The second one is mostly used for tables is because of the pairs() function. This guy explains better of what does pairs() do.

local tbl = {
[1] = "hi",
["hello"] = "Roblox"
}

for a, b in pairs(tbl) do
print(a, b)
-- 1 hi
-- hello Roblox
end


Now that we know what is a for loop, we can now use it:

local characterCFrame = character:GetPivot() -- similar to character.HumanoidRootPart.CFrame
for rotation = 1, 360 do
character:PivotTo(characterCFrame * CFrame.Angles(0, math.rad(rotation), 0)) -- PivotTo is the same as setting/changing a part/model's CFrame
task.wait() -- we will add this just incase if it breaks the game
end
character:PivotTo(characterCFrame) -- returns to original rotation

1
That was fantastic! Completely answered the question! If I could trouble you for one additional bit of help, is there a way to make the rotation go faster? Never2Humble 90 — 19d
1
You can change the increment. For example, if I do for rotation = 1, 360, 2 do it will spin 2x faster T3_MasterGamer 1686 — 18d
1
Perfect! Everything is solved! Thank you so much! Never2Humble 90 — 18d
0
You’re welcome! <3 T3_MasterGamer 1686 — 18d