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

How to stop this script from looping over and over?

Asked by 6 years ago
local Temp
Temp = workspace:WaitForChild("Temp").Changed:Connect(function(TempCheck)

while true do
    wait(2)
    if TempCheck == 200 then
    game.Workspace.Check1.Disabled = true
    Temp:Disconnect()
    local Melt = Instance.new("Hint", game.Workspace)
    Melt.Parent = game.Workspace
    Melt.Name = 'CoreHot'
    Melt.Text = '!Core is heating up!'
    script.Warning1:Play()
    wait(3)
end
end
end)

How to stop it from looping over and over.

1 answer

Log in to vote
0
Answered by 6 years ago

You're using a while true do loop. while true do loops loop over and over again and are unnecessary in this case.

local Temp
Temp = workspace:WaitForChild("Temp").Changed:Connect(function(TempCheck)


    wait(2)
    if TempCheck == 200 then
    game.Workspace.Check1.Disabled = true
    Temp:Disconnect()
    local Melt = Instance.new("Hint", game.Workspace)
    Melt.Parent = game.Workspace
    Melt.Name = 'CoreHot'
    Melt.Text = '!Core is heating up!'
    script.Warning1:Play()
    wait(3)
end

end)

It isn't very good to place a while true do loop inside an event, as it will no longer listen for it, and keep looping over and over.

0
thx kyanoke11 15 — 6y
0
No problem! brokenVectors 525 — 6y
Ad

Answer this question