So I'm trying to get out of a Function that continues to run. I have tried to work around it by making an "if then end" but since it's not updating the state of that variable once the variable is "true" (let's say) it continues the function within the "if then" even when later that variable to set to "false", it doesn't read an update. I'm sure there is a way to do this but not sure.
TL;DR I'm not sure how to say "if this variable == false at ANY POINT stop running this function"
Code I'm Working With (I know it's messy oops)
~~~~~~~~~~~~~~~~~
-- Ignore the fact some variables are missing....don't feel like making this longer than it already is local _check = true function mouseMove() local posX, posY, posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z Preview.Position = Vector3.new(posX,posY,posZ) print ("Im Still Running") -- THIS IS PROVING THAT FUNCTION NEVER STOPS mouse.Button1Down:connect(function() print("BOOP") ply.Items.Oof.Value = false _clone.Position = Preview.Position script.Parent.Parent.Parent.ScreenGui.MyButton["De 1"].ItemName.Text = "" _check = false Preview:Destroy() end) end if ply.Items.Oof.Changed:connect(function() if ply.Items.Oof.Value == true then game:GetService("UserInputService").InputBegan:connect(function(_inOb,gameProcessedEvent) if _inOb.KeyCode == Enum.KeyCode.One then _check = true if _check ~= false then mouse.Move:connect(mouseMove) --Once line Get's here it runs above function every mouse movement, this is the issue. Somehow it get's here when I set _check = false end end end) end end) then end
~~~~~~~~~~~~~~~~~
I have found a temporary solution by just disabling and re-enabling the script. Not a "bug fix" but a way from keeping that bug happen. Hey on the bright side the way I made the disabling and re-enabling made 1 less script run until the point it's needed.