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.