-
What do you want to achieve? Keep it simple and clear!
I want to make the character look at the mouse pointer but only in the x and z axes. -
What is the issue? Include screenshots / videos if possible!
The script works but the character keeps swaying back and forth. It only bugs for R6 character, but I want to keep the game R6. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
ChatGPT didn’t fare well this time either. I searched a bit through the forum but I didn’t see any. I tried setting CFrame differently but nah didn’t work.
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local rayParams = RaycastParams.new() do
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {character}
end
local function getMousePos()
local length = 1000
local mousePos = UIS:GetMouseLocation()
local ray = workspace.CurrentCamera:ScreenPointToRay(mousePos.X, mousePos.Y)
local raycast = workspace:Raycast(ray.Origin, ray.Direction * length, rayParams)
if raycast then
return raycast.Position
end
return ray.Direction * length
end
while task.wait() do
local mousePos = getMousePos()
character.PrimaryPart.CFrame = CFrame.new(character.PrimaryPart.Position) * CFrame.lookAt(character.PrimaryPart.Position, Vector3.new(mousePos.X, character.PrimaryPart.Position.Y, mousePos.Z)).Rotation
end