For some reason, this local script will keep running even when it's not suppose to. I tried using a variable to make it stop running, I also tried disconnecting the function as well. I've been having this problem for a long time now, and I'm getting real desperate, so I'm putting a lot of context, just to find out what the real problem is. The local script is parented to StarterPlayerScripts.
I'll only just show a simple example of what this local script pretty much look like:
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Z then
game.ReplicatedStorage.MouseFacing:Fire(true)
end
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Z then
game.ReplicatedStorage.MouseFacing:Fire(false)
end
end)
end)
Local Script
local conn
conn = game.ReplicatedStorage.MouseFacing.Event:Connect(function(run)
local player = game.Players.LocalPlayer
local character = player.Character
local cam = game.Workspace.CurrentCamera
local equipped = false
local tor = character.HumanoidRootPart
local hum = character.Humanoid
local Mouse = player:GetMouse()
local prev_mousehit
local move
move = Mouse.Move:Connect(function()
if not run then
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))
print("why is it working") -- even when the variable "run" is set to false, it still would print this.
end
else
hum.AutoRotate = true
end
end)
end)
Btw, I tried disconnecting conn, but it doesn't fix the problem for some reason and it won't let me run the script again when I want it to.

1 comment
Try making the if statement: if run == false then return move:Disconnect()