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?
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)