Character Flops

Hello Devs,
So I’m workin on a mode with a tool and ive ran into a problem where the character would flop on the ground instead of following the mouse how can I fix this?

Code:

-- Services & Variables --
local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local TweenService = game:GetService('TweenService')
--
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = script.Parent.Parent.Parent
local Camera = game.Workspace.CurrentCamera
--

-- Values --
local MousePos = nil
local Equipped = true
--

-- Main --
RunService.RenderStepped:Connect(function()
	if Equipped == true and (Camera.Focus.Position - Camera.CoordinateFrame.Position).Magnitude > 1 then
		local RootPart = Character.HumanoidRootPart
		local RY = Camera.CFrame:ToOrientation()
		Character.Humanoid.AutoRotate = false
		if Mouse.Hit.Position ~= MousePos then
			RootPart.CFrame = CFrame.new(RootPart.Position) * CFrame.fromOrientation(Mouse.Hit.Position.X,RY,Mouse.Hit.Position.Z)
			MousePos = Mouse.Hit.Position
		end
	else
		Character.Humanoid.AutoRotate = true
	end
end)
--

Why not use CFrame.LookAt?

local Pos = Vector3.new(Mouse.Hit.X,RootPart.Position.Y,Mouse.Hit.Z) -- Yes, a CFrame has X,Y,Z properties just like a Vector3
RootPart.CFrame = CFrame.LookAt(RootPart.Position,Pos)

https://medal.tv/games/roblox-studio/clips/FLfHPOk2D93z_/9NwMquHtOULm?invite=cr-MSx0ZnYsMTI3NzYwNjY2LA

It still lags the camera. Is there a way I can use lerp or TweenService so it doesnt look like its lagging

I get this error.


  • Updated Code:
-- Services & Variables --
local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local TweenService = game:GetService('TweenService')
--
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = script.Parent.Parent.Parent
local Camera = game.Workspace.CurrentCamera
--

-- Values --
local MousePos = nil
local Equipped = true
--

-- Main --
RunService.RenderStepped:Connect(function()
	if Equipped == true and (Camera.Focus.Position - Camera.CoordinateFrame.Position).Magnitude > 1 then
		local RootPart = Character.HumanoidRootPart
		local Pos = Vector3.new(Mouse.Hit.X,RootPart.Position.Y,Mouse.Hit.Z)
		Character.Humanoid.AutoRotate = false
		if Mouse.Hit.Position ~= MousePos then
			RootPart.CFrame:Lerp(RootPart.Position,Pos)
			MousePos = Mouse.Hit.Position
		end
	else
		Character.Humanoid.AutoRotate = true
	end
end)