Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you end a script without looping itself and rebeginning itself?

So, I'm making my own Computer Core but I don't know how to end a script. Ive tried so many things but the script will repeat itself.

while true do
	wait(1)
	if game.Workspace.Temp.Value > 2000 then
		script.Alert1:Play()
		local msg = Instance.new("Message")
		msg.Parent = game.Workspace
		msg.Name = 'Selfdestruct'
		wait(5)
		script.Alert1:Stop()
		msg.Text = "SelfDestruct in ----"
		script.Self6mins:Play()
		wait(5)
		msg.Text = "SelfDestruct in 6 Minutes"
		game.Workspace.Selfdestruct:remove()
		wait(3)
		script.Self6mins:Stop()
		script.Disabled = true
	end
end

I even tried to disable the script at the end, even that won't work. Can somebody help me out?

1 answer

✓ Accepted answer

Don't loop things to constantly check them. The best way is using the changed event. Then you disconnect it once it reaches over 2000.

Does this work?

local con
con = workspace:WaitForChild("Temp").Changed:Connect(function(new)
	if new > 2000 then
		con:Disconnect() -- to stop this code from running again
		script.Alert1:Play()
		local msg = Instance.new("Message")
		msg.Parent = game.Workspace
		msg.Name = 'Selfdestruct'
		wait(5)
		script.Alert1:Stop()
		msg.Text = "SelfDestruct in ----"
		script.Self6mins:Play()
		wait(5)
		msg.Text = "SelfDestruct in 6 Minutes"
		game.Workspace.Selfdestruct:Destroy() -- remove is deprecated, use Destroy.
		wait(3)
		script.Self6mins:Stop()
		script.Disabled = true
	end
end)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.