How do i make character body look at x and z of mouse position?

Im trying to make the body of the character look at the mouse position once he is holding certain tool and an input began, after the input end or he stops holding the tool he gets normal again. How can i do this?

I got it

local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local character = player.Character

local tool = script.Parent
local event = game.ReplicatedStorage.Mecanics.LookXZ
local equip = false
local connection 

tool.Equipped:Connect(function()
	equip = true
end)

tool.Unequipped:Connect(function()
	equip = false
end)

uis.InputBegan:Connect(function(input, GPE)	
	if input.KeyCode == Enum.KeyCode.T then
		print(equip)
		if equip == true then
			local root = character:FindFirstChild("HumanoidRootPart")			
			connection = RunService.RenderStepped:Connect(function()
				local mouse = player:GetMouse()
				local rootpos, mousepos = root.Position, mouse
				root.CFrame = CFrame.new(rootpos, Vector3.new(mouse.Hit.Position.X, rootpos.Y,mouse.Hit.Position.Z ))
			end)
		end
	end
end)

uis.InputEnded:Connect(function(input, GPE)
	if input.KeyCode == Enum.KeyCode.T then
		connection:Disconnect()
	end
end)

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