I’m creating a simple script where your character will face wherever your mouse is pointing. I got it half working but putting your mouse behind the character doesn’t work. I’m not good with math and I don’t know how to fix this. Any help is much appreciated.
local player = game.Players.LocalPlayer;
local mouse = player:GetMouse();
local character = player.Character or player.CharacterAdded:Wait();
local root = character:WaitForChild("HumanoidRootPart");
game:GetService("RunService").RenderStepped:Connect(function(step)
local rx, ry, rz = mouse.Hit:ToOrientation();
root.CFrame = CFrame.new(root.CFrame.p) * CFrame.fromOrientation(0, ry, 0);
end)
local Tweens = game:GetService("TweenService")
local Run = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()
Run.RenderStepped:Connect(function()
local Tween = Tweens:Create(HRP, TweenInfo.new(0.2), {CFrame = CFrame.lookAt(HRP.CFrame.Position, Vector3.new(Mouse.Hit.Position.X, HRP.CFrame.Position.Y, Mouse.Hit.Position.Z))})
Tween:Play()
end)