Roblox character follow mouse bug!

Hey guys!

I made these muskets for my tech company and my British group and im having a problem with the rotation script.

WHAT THIS SCRIPT DOES

Once enabled makes players body follow the mouse.

THE BUG

When I disable the script the player gets locked onto a grid and cant turn around or move at all.

https://gyazo.com/2ea23034ba3706cb584592609e4c54b8

CODE



local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
	tor = character:WaitForChild("HumanoidRootPart")
	hum = character:WaitForChild("Humanoid")
end
local cam = game.Workspace.CurrentCamera
local equipped = false
local tor = character.HumanoidRootPart
local hum = character.Humanoid
player.CharacterAdded:Connect(function()
	character = player.Character
	tor = character:WaitForChild("HumanoidRootPart")
	hum = character:WaitForChild("Humanoid")
end)
local Mouse = player:GetMouse()
local prev_mousehit

script.Parent.Equipped:Connect(function()
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
	hum.AutoRotate = true
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if equipped == true and (cam.Focus.p-cam.CoordinateFrame.p).magnitude > 1 then
		hum.AutoRotate = false
		if Mouse.Hit.p ~= prev_mousehit then
			tor.CFrame = CFrame.new(tor.Position, Vector3.new(Mouse.Hit.p.x,tor.Position.y,Mouse.Hit.p.z))
			prev_mousehit = Mouse.Hit.p
		end
	else
		hum.AutoRotate = true
	end
end)

Any help would be loved.

3 Likes

Maybe try to trun on AutoRotate inside the Humanoid.

1 Like

I know that constantly CFraming characters often leads to issues that restrict movement, instead of rotating the character via CFrame try using a BodyGyro, they are much more compatible with characters. Insert one in the character and change the BodyGyro.CFrame property to see if that fixes the issue.

2 Likes

Yeah that’s a good way to fix that issue.

Thanks I enabled this after disabled the script and it worked :heart:

2 Likes