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)
--
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)
-- 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)