Changing the Direction of an Animation to Face where the mouse is pointing

So I recently posted about a fly script, and had someone in Discord help me with it, but I have one problem, I want the animation to follow your mouse. Basically, what happens is whichever direction you move to with ‘WASD’ changes the animation to face that way, but I want it to face the direction I point my mouse. Could anyone help me with this? All help is appreciated!

https://imgur.com/a/7emkcrK

local id = (AnimID)
repeat wait() until (game.Players.LocalPlayer.Character:WaitForChild("Humanoid") ~= nil)
local animObj = Instance.new("Animation")
animObj.AnimationId = "rbxassetid://" .. id
local anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animObj)
anim.Looped = true
local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction
local character = player.Character or player.CharacterAdded:Wait() --Lets wait for the character to be added
local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart")) --Lets create BodyVelocity and parent it to the HumanoidRootPart of our player
local speed = 100
local Bind = false
local UIS = game:GetService("UserInputService")

BV.MaxForce = Vector3.new()
UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.F and not Bind then
        Bind = true
        BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
          anim:Play()
    elseif input.KeyCode == Enum.KeyCode.F and Bind then
        Bind = false
        BV.MaxForce = Vector3.new()
        anim:Stop()
    end
end)
UIS.InputChanged:Connect(function() --Detect when the mouse moves
BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * speed --Set Velocity to the mouse position everytime the mouse moves
end)```

Edit: Fixed video.

Just make the player face the mouse.

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position,mouse.Hit.Position)

If you want it to be smooth then use BodyGyro and for those people that says its deprecated, it still works though I know it wont get updated anymore. Oh and uh if you want it to still lay on the ground then you can multiply the CFrame by CFrame.angles to get the perfect orientation.

1 Like

Oh hey OctaLua, you commented on my last post.

1 Like

So I added this in, and I can’t move, and just slowly float upwards. It says CFrame cannot be assigned to… then it just cuts off.

Edit: new code. BV.Velocity.CFrame = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * speed

Just change the RootParts cFrame itself, if you want to do it with bodymovers then use bodygyro.