How can I disable a Script with another Script whilst the Script I want to disable is running?

I have a Local Script in the StarterCharacterScripts that enables view bobbing for the Player. This is for a single-player game. I’ve made a setting in a GUI to toggle view bobbing, by disabling the Local Script that enables view bobbing for the player. However, the Local Script gets disabled for view bobbing, but view bobbing still works. I’m looking for a way to disable and enable a Local Script whilst it’s running. I have also tried other methods of disabling the view bobbing script but nothing seems to work.

Here is my code

View Bobbing Setting Toggle:

-- View Bobbing Setting
ViewBobbingSetting.ToggleBtn.MouseButton1Click:Connect(function()
	if ViewBobbingSetting.ToggleBtn.IsEnabled.Value == true then
		ViewBobbingSetting.ToggleBtn.Text = "OFF"
		ViewBobbingSetting.ToggleBtn.BackgroundColor3 = Color3.fromRGB(199, 41, 41)
		events:WaitForChild("ViewBobbingChanged"):FireServer(ViewBobbingSetting)
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing").Enabled = false
		print("View Bobbing OFF")
	elseif ViewBobbingSetting.ToggleBtn.IsEnabled.Value == false then
		events:WaitForChild("ViewBobbingChanged"):FireServer(ViewBobbingSetting)
		ViewBobbingSetting.ToggleBtn.Text = "ON"
		ViewBobbingSetting.ToggleBtn.BackgroundColor3 = Color3.fromRGB(53, 207, 71)
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing").Enabled = true
		print("View Bobbing ON")
	end	
end)

This disables view bobbing (Server Script)

-- View Bobbing
events:WaitForChild("ViewBobbingChanged").OnServerEvent:Connect(function(player, ViewBobbingSetting)
	ViewBobbingSetting:WaitForChild("ToggleBtn"):WaitForChild("IsEnabled").Value = not ViewBobbingSetting:WaitForChild("ToggleBtn"):WaitForChild("IsEnabled").Value
	
	if ViewBobbingSetting:WaitForChild("ToggleBtn"):WaitForChild("IsEnabled").Value == false then
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing"):WaitForChild("CanWork").Value = false
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing").Enabled = false
	else
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing").Enabled = true
		game.StarterPlayer:WaitForChild("StarterCharacterScripts"):WaitForChild("ViewBobbing"):WaitForChild("CanWork").Value = true

	end 
end)

View bobbing script (Not created by me!)

local runService = game:GetService("RunService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

function updateBobbleEffect()
	local currentTime = tick()
	if humanoid.MoveDirection.Magnitude > 0 then
		local bobbleX = math.cos(currentTime * 10) * .35
		local bobbleY = math.abs(math.sin(currentTime * 10)) * .35

		local bobble = Vector3.new(bobbleX, bobbleY, 0)

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25)
	else
		humanoid.CameraOffset = humanoid.CameraOffset * .75
	end
end


while true do
	task.wait(.01)
	if script.Enabled == false then
		return false
	else
		task.spawn(updateBobbleEffect)
	end
end

I would try to put the local script inside replicated storage, a place where it wouldn’t run, when the player needs it, parent It to the player, then add a AncestryChanged event, or just enable it when it moves into the player. Same thing with disabling it.

Once a script is running, you cannot disable it, you can only end the script or break a continuous loop. I would recommend getting the view bobbing script to monitor an Attribute on the character which is Enabled/Disabled as required instead.

Other scripts can disable and even destroy other scripts, running or not. Just locate the script from the other script and disable it.