Any way to make my script up to speed with my mouse?

So, I have this script that turns moves the players character along with your mouse movement, but its slow and doesn’t completely keep up to speed with the mouse, any way to modify this to make it move at the same speed as the mouse? Here is the script.

Tool = script.Parent
gyro = Instance.new("BodyGyro")
script:WaitForChild("Gyro").Value = gyro 

onMouseMove=function(mouse)
	local vCharacter = Tool.Parent
	if vCharacter ~= nil then 
		local tp = vCharacter.Humanoid.TargetPoint
		tp = Vector3.new(tp.X,Tool.Parent.UpperTorso.Position.Y,tp.Z) 
		local dir = (tp - Tool.Parent.UpperTorso.Position).unit
		local spawnPos = Tool.Parent.UpperTorso.Position
		local pos = spawnPos + (dir * 1000)
		script.Gyro.Value.cframe = CFrame.new(pos,  pos + dir)
	end
end

onEquipped=function(mouse)
	for i,k in pairs(Tool.Parent.UpperTorso:GetChildren()) do
		if k:IsA("BodyGyro") then 
			k.Parent=nil 	
		end
	end
	wait(0.1) 
	script.Gyro.Value.Parent = Tool.Parent:findFirstChild("UpperTorso")
	script.Gyro.Value.maxTorque = Vector3.new(300,300,300)
	mouse.Move:connect(function() onMouseMove(mouse) end)
end 

onUnequipped=function()
	script.Gyro.Value.Parent = nil 
	wait(0.01) 
	for i,k in pairs(Tool.Parent.UpperTorso:GetChildren()) do
		if k:IsA("BodyGyro") then 
			k.Parent=nil 	
		end
	end
end 

Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)
2 Likes

Can’t you call the WalkTo function on the humanoid to make the player walk to wherever the mouse is. You can easily speed it up / slow it down by changing the WalkSpeed?

I believe he isn’t trying to make the player walk to the mouse, he wants the player to rotate to face the mouse.

Oh alright,

Character:SetPrimaryPartCFrame(CFrame.new(Character.CFrame.p, Mouse.Hit.p))

This will rotate the ENTIRE character towards the mouse. If you want to make it more smooth u can replace setprimarypartcframe with tweenservice or lerping. This will probably be an easier way than using gyros.

Im confused? Any further explaination

Sets the primary character part CFrame(HumanoidRootPart) and points it to Mouse.Hit
Although the script is wrong, as it’s supposed to be Character.HumanoidRootPart.Position or Character:GetPrimaryPartCFrame().p

Changing the maxtorque of the BodyGyro should do it. It needs to be a little higher than that.