Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

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)
0
Thank you! kyanoke11 15 — 6y
Ad

Answer this question