How can I make it where the player can rotate on the Y and Z at the same time while following the mouse?

I’ve been stuck trying to find how would I be able to make the player rotate up and down and left to right, but when I try to do both at the same time it just does the first axis.

local tool = script.Parent
local Player = game:GetService("Players").LocalPlayer
local c = Player.Character or Player.CharacterAdded:Wait()
local hrp, hum = c:WaitForChild("HumanoidRootPart"), c:WaitForChild("Humanoid")
local rs = game:GetService("RunService")
local Holding = false
local mouse = Player:GetMouse()

local function FaceMouse()

	local bp = Instance.new("BodyPosition")
	bp.MaxForce = Vector3.new(900000, 900000, 900000)
	bp.P = 7000
	bp.D = 500
	bp.Position = hrp.Position
	bp.Parent = hrp

	local bg = Instance.new("BodyGyro")
	bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	bg.P = 9000
	bg.D = 50
	bg.CFrame = CFrame.new(hrp.Position, CFrame.new(mouse.hit.p.X, hrp.Position.Y, mouse.hit.p.Z).p)
	bg.Parent = hrp

	return bp, bg
end

tool.Activated:Connect(function()
	local bp, bg = FaceMouse()
	local cur = tick()
	
	repeat 
		bg.CFrame = CFrame.new(hrp.Position, CFrame.new(mouse.hit.p.X, hrp.Position.Y, mouse.hit.p.Z).p)
		rs.Heartbeat:Wait() 
	until (tick() - cur) >= 5
	bp:Destroy()
	bg:Destroy()
	
end)

This is what I have so far I want the hrp position to move with the X and Y of the mouse.

2 Likes

You can do

repeat wait()
 hrp.CFrame = CFrame.new(hrp.Position,Mouse.Hit.Position)
until (tick() - cur) >= 5

1 Like

https://gyazo.com/f7e6b82e42875eb4ede0f3208ff43c79

it works a little but it stutters

1 Like

umm thats because your mouse is pointing at your character arm Try

bg.CFrame = CFrame.lookAt(hrp.Position, mouse.hit.Position)

1 Like

It works been trying to do this for a while I’m new to scripting this helps a lot thank you some much man

local tool = script.Parent
local Player = game:GetService("Players").LocalPlayer
local c = Player.Character or Player.CharacterAdded:Wait()
local hrp, hum = c:WaitForChild("HumanoidRootPart"), c:WaitForChild("Humanoid")
local rs = game:GetService("RunService")
local Holding = false
local mouse = Player:GetMouse()

local function FaceMouse()

	local bp = Instance.new("BodyPosition")
	bp.MaxForce = Vector3.new(900000, 900000, 900000)
	bp.P = 7000
	bp.D = 500
	bp.Position = hrp.Position
	bp.Parent = hrp

	local bg = Instance.new("BodyGyro")
	bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	bg.P = 9000
	bg.D = 50
	bg.CFrame = CFrame.new(hrp.Position, CFrame.new(mouse.hit.p.X, hrp.Position.Y, mouse.hit.p.Z).p)
	bg.Parent = hrp

	return bp, bg
end

tool.Activated:Connect(function()
	local bp, bg = FaceMouse()
	local cur = tick()
	
	repeat wait()
		hrp.CFrame = CFrame.new(hrp.Position,mouse.Hit.Position)
		bg.CFrame = CFrame.lookAt(hrp.Position, mouse.hit.Position)
	until (tick() - cur) >= 5
	bp:Destroy()
	bg:Destroy()
	
end)
1 Like
local tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = character:WaitForChild('Humanoid')
local Position = Mouse.Hit.Position

local AimState = false



tool.Activated:Connect(function()
	
	AimState = true
	
	
	game:GetService('RunService').RenderStepped:Connect(function()
		if AimState == true then
			local Position = Mouse.Hit.Position
			character.HumanoidRootPart.Anchored = true
			character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, Position)		
		else
			character.HumanoidRootPart.Anchored = false	
		end
		
	end)
	task.wait(2)
	AimState = false
end)

Made a solution for it now.