Animation Scripting Help

So My Character Animation Bug Idk Why:


And Here My Script:

mouse.Icon = 'http://www.roblox.com/asset/?id=172802980'
game:GetService("StarterGui"):SetCoreGuiEnabled("Health", false)
game:GetService("StarterGui"):SetCoreGuiEnabled("Chat", false)

while game.Players.LocalPlayer.Character do
    task.wait(0.)
    local char = game.Players.LocalPlayer.Character
    if char:FindFirstChild("Torso") and char:FindFirstChild("HumanoidRootPart") then
        local Torso = char.Torso
        local HumanoidRootPart = char.HumanoidRootPart
        Torso.Orientation = Vector3.new(0,Torso.Orientation.Y,0)
        HumanoidRootPart.Orientation = Vector3.new(0,HumanoidRootPart.Orientation.Y,0)
    end
end

You Can Help. I Want To Make Char Stands

1 Like

There’s quite a lot of things to touch up on here.

First of all, to resolve your issue.
Changing the Position or Orientation of a part will break any joints it has. This means that when you change the orientation of your root part or torso, you’re breaking the joints of the character, resulting in the weird behavior you see.

To avoid this, you have to change the CFrame instead.
You can construct a CFrame you need like so:

CFrame.new(Part.Position) * CFrame.Angles(0, math.rad(Part.Orientation.Y), 0)

You also don’t need to be constantly setting the rotation of both the torso and root part. Just doing the root part is enough.

Lastly, loops that need to run constantly, or each frame, should not be done using while-do, but rather through RunService.PreRender.

Putting all this together, you final script should look something like this:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

RunService.PreRender:Connect(function()
    local Character = Players.LocalPlayer.Character
    if not Character then return end
    if not Character:FindFirstChild("HumanoidRootPart") then return end

    local RootPart = Character.HumanoidRootPart
    RootPart.CFrame = CFrame.new(RootPart.Position) * CFrame.Angles(0, math.rad(RootPart.Orientation.Y), 0)
end)

I hope this helps!

2 Likes

Thanks You So Mucha It Worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.