How can I make the player character rotate towards the mouse position temporarily?

I’ve been trying for a while to rotate the player’s character to the position of the mouse X, I have gotten some scripts that do that but they are permanently, and what I’m looking for is that it follows the mouse when it is clicked.

2 Likes

try this:

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse();

local character = player.Character or player.CharacterAdded:Wait();

mouse.Button1Down:Connect(function()
	local mousePos = mouse.Hit.Position;
	local charPos = character.HumanoidRootPart.Position;
	
	local angle = math.atan((charPos.X - mousePos.X)/(charPos.Z - mousePos.Z));
	character.HumanoidRootPart.CFrame *= CFrame.Angles(0, angle, 0)
end)

I am not sure if it works, and can’t test it right now

This better. took me 4 months to figure this out.

local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local Character = player.Character 
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local mouse = player:GetMouse()
local aim = false
local runService = game:GetService("RunService")

runService.RenderStepped:Connect(function()
	if aim == true then
		local rx, ry, rz = Camera.CFrame:ToOrientation()
		rootPart.CFrame = CFrame.new(rootPart.CFrame.p) * CFrame.fromOrientation(0, ry, 0)
	end
		
end)
mouse.Button1Down:Connect(function()
	aim = true
end)
mouse.Button1Up:Connect(function()
	aim = false
end)

5 Likes

Omg man thank you very much[quote=“jonny377, post:3, topic:1149589, full:true”]
This better. took me 4 months to figure this out.

local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local Character = player.Character 
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local mouse = player:GetMouse()
local aim = false
local runService = game:GetService("RunService")

runService.RenderStepped:Connect(function()
	if aim == true then
		local rx, ry, rz = Camera.CFrame:ToOrientation()
		rootPart.CFrame = CFrame.new(rootPart.CFrame.p) * CFrame.fromOrientation(0, ry, 0)
	end
		
end)
mouse.Button1Down:Connect(function()
	aim = true
end)
mouse.Button1Up:Connect(function()
	aim = false
end)

[/quote]

Omg man thank you very much

3 Likes