Is there a way to entirely STOP a script?

Just as the title says, is there a way to entirely stop a script dead in its tracks? I’ve been searching and searching for an answer but there doesn’t seem to be any solution.

1 Like

Using BaseScript.Disabled to true it will terminate the current thread and prevent the script from starting new threads until it’s set to false. Read more on it here.

1 Like

Yes, the documentation might say that but in reality it does not terminate the thread, it continues it until all the code has been run. I’ve tried.

1 Like

Can you give your use case? Most of the time you can use a simple if statement instead. Disabling scripts isn’t really needed during runtime.

local disabled = true --boolean
if not disabled then
--run code
end
1 Like

You can use

break

in loops and they would stop, you could combine it like this for disabling both loop, script

local stopMyLoop = false
for gametime=10,0,-1 do
   if gametime == 5 then stopMyLoop = true end
   if stopMyLoop == true then script.Disabled = true; break end
   wait(1)
end
1 Like
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
while workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable do
	for i=1,#workspace.IntroCamParts:GetChildren(),2 do
		local ts = game:GetService("TweenService")
		cam = workspace.CurrentCamera
		local ti = TweenInfo.new(10,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0)
		cam.CFrame = workspace.IntroCamParts["Part"..i].CFrame
		local tween = ts:Create(cam,ti,{CFrame = workspace:WaitForChild("IntroCamParts"):WaitForChild("Part"..tostring(i+1)).CFrame})
		tween:Play()
		wait(10)
	end
end

In another script the camera should be set to Custom when a button is clicked but if that happens the script will continue the tween the amount of times it has been given. I don’t want this, so i need a solution that’ll instantly just stop it. (also sorry if the code is a bit sloppy/bad, i’m a beginner.)

btw, trying ur solution right now steven.

1 Like

This worked for my case, thanks!

1 Like

To close out of the main scope, you can also just use return. For example, in that case, replacing break with return would cause the script to completely stop even if you added something after the loop. Example:

local x = 3

do return end

print(x) --> nothing prints
3 Likes