This local script makes your character face your mouse, but I want it stop when I want it to. However, I tried disconnecting, return and disabling and still doesn't work. It's parented to StarterPlayerScripts. I put a print to check if it was being disconnected, and it is, but still is running. How do I fix this? Someone please help!!
local conn
conn = game.ReplicatedStorage.MouseFacing.Event:Connect(function(run)
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
local tor = character:WaitForChild("HumanoidRootPart")
local 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
local move
move = Mouse.Move:Connect(function()
if not run then
print("Disconnected")
move:Disconnect()
return
end
if (cam.Focus.Position-cam.CoordinateFrame.Position).magnitude > 1 then
hum.AutoRotate = false
if Mouse.Hit.Position ~= prev_mousehit then
prev_mousehit = Mouse.Hit.Position
tor.CFrame = CFrame.new(tor.Position, Vector3.new(Mouse.Hit.Position.x,Mouse.Hit.Position.y,Mouse.Hit.Position.z))
end
else
hum.AutoRotate = true
end
end)
end)

2 comments
Return is used to give back information when a function is called. Disabing is inconsistant. So id just recomend creating a bool variable (only true or false) and have your code run while the variable is true. Then toggling the variable seperatly.
Tried it, it still runs after setting the variable to false. Is there anything that could cause it to continue working?