Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make humanoid spin in a complete circle?

Asked by 2 years ago

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.

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

Thanks!

1 answer

Log in to vote
2
Answered by 2 years ago

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.

01for number = 1, 10 do -- if increment is not set, it is automatically set to 1 as the default
02    print(number) -- prints 1 up to 10
03end
04 
05for odd = 1, 9, 2 do
06    print(odd) -- prints all odd numbers from 1 to 9 (1, 3, 5, 7, 9)
07end
08 
09for even = 2, 10, 2 do
10    print(even) -- prints all even numbers from 2 to 10 (2, 4, 6, 8, 10)
11end

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

1function test()
2    return "hi", "hello", "Roblox"
3end
4 
5for a, b, c, d in test do
6    print(a, b, c, d) -- hi hello Roblox nil
7    -- the fourth prints nil because a fourth value wasn't returned by the function
8end

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

01local tbl = {
02    [1] = "hi",
03    ["hello"] = "Roblox"
04}
05 
06for a, b in pairs(tbl) do
07    print(a, b)
08    -- 1 hi
09    -- hello Roblox
10end

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

1local characterCFrame = character:GetPivot() -- similar to character.HumanoidRootPart.CFrame
2for rotation = 1, 360 do
3    character:PivotTo(characterCFrame * CFrame.Angles(0, math.rad(rotation), 0)) -- PivotTo is the same as setting/changing a part/model's CFrame
4    task.wait() -- we will add this just incase if it breaks the game
5end
6character: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 — 2y
1
You can change the increment. For example, if I do `for rotation = 1, 360, 2 do` it will spin 2x faster T3_MasterGamer 2189 — 2y
1
Perfect! Everything is solved! Thank you so much! Never2Humble 90 — 2y
0
You’re welcome! <3 T3_MasterGamer 2189 — 2y
Ad

Answer this question