Align Orientation: How do I make my character look at my cursor?

I’ve been attempting to make a skill that makes you freeze midair while holding or charging the skill while also being able to look around. Kinda like Vetex’s games like Arcane Adventure. I’m using OnionDev’s script and altered it a bit, but it gives an error

image_2023-08-14_092028523

OnionDev’s Post

Local Script:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Torso = Character:FindFirstChild("Torso")
local RootPart = Character:FindFirstChild("HumanoidRootPart")

local attatch = Instance.new("Attachment", RootPart)
local AlignOrien = Instance.new("AlignOrientation", RootPart)

AlignOrien.Attachment0 = attatch
AlignOrien.Mode = Enum.OrientationAlignmentMode.OneAttachment

local function findTheAngle(positionA, PositionB)
	local CFRAME = CFrame.new(positionA, PositionB)
	local targetX, targetY, targetZ = CFRAME:ToEulerAnglesXYZ()
	local finalAngle = CFrame.Angles(targetX,targetY,targetZ)
	return finalAngle
end

local mouse = Player:GetMouse()
local runservice = game:GetService("RunService")

runservice.RenderStepped:Connect(function()
	AlignOrien.CFrame = findTheAngle(RootPart.Position, mouse.Hit.Position)
end)
1 Like

When CharacterAdded is fired, it is only an empty model. You have to run WaitForChild instead of FindFirstChild when getting HumanoidRootPart. Be advised, unless you are using R6 rigs, “Torso” isn’t a thing. Besides, you never actually use it in the script?

1 Like

Thank you, for correcting me.
I am using an R6 rig and was testing multiple ways to achieve the goal, which is why I attempted to get the torso.

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