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

How do I break this while loop, and run a seperate line of code for when coretemp equals 8999?

Asked by 6 years ago

So the problem is, if I implement the Meltdown Code I know it's going to constantly run infinitely, and I don't want that. So how can I make it only run once, while I have a while loop present?

coretemp = script.Parent.coretemp
heatmult = script.Parent.heatmult
coolmult = script.Parent.coolmult

coretemp.Value = 2000 -- Starting Core Temperature
heatmult.Value = 1 -- Starting heat multiplier
coolmult.Value = 0 -- Starting cool multiplier

corestatus = "SAFE"

function heatgeneration()
    wait(1)
    if heatmult.Value > coolmult.Value then
        coretemp.Value = coretemp.Value + 1 * heatmult.Value
    elseif coolmult.Value > heatmult.Value then
        coretemp.Value = coretemp.Value - 1 * coolmult.Value
    end
end

function status()
    if heatmult.Value ~= coolmult.Value then
        heatgeneration()
    end
    script.Parent.Name = "Core Temp: "..coretemp.Value.."c, "..corestatus
    print(script.Parent.Name)
    if coretemp.Value >= 8999 then
        corestatus = "DANGER"
    else
        corestatus = "SAFE"
    end
    if corestatus == "DANGER" then
        script.Parent.Core.Size = Vector3.new(15.75,15.75,15.75)
        script.Parent.Shield.Size = Vector3.new(16,16,16)
    else
        script.Parent.Core.Size = Vector3.new(3.75,3.75,3.75)
        script.Parent.Shield.Size = Vector3.new(4,4,4)      
    end
end



while wait() do
    status()
end

0
This script is the code of a Nuclear Reactor I am building. Inevitable_Judgement -10 — 6y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
while wait() do 
    if coretemp.Value < 9000 then 
        status()

    elseif coretemp.Value > 8999 then 
        coretemp.Value = 9000
        break 
    end
end
0
don't know what you mean by 'seperate line of code' hellmatic 1523 — 6y
0
Basically, I was going to have a seperate function for the meltdown code without creating a new script. But thank you you've fixed my problem. I wasn't sure if this was gonna work. Inevitable_Judgement -10 — 6y
0
I'm gonna have to restructure the whole script I'm afraid. But now I know how to do it. :) Inevitable_Judgement -10 — 6y
Ad

Answer this question