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

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

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

1 comment

0

This script is the code of a Nuclear Reactor I am building.

1 answer

while wait() do 
	if coretemp.Value < 9000 then 
		status()
	
	elseif coretemp.Value > 8999 then 
		coretemp.Value = 9000
		break 
	end
end

3 comments

0

don't know what you mean by 'seperate line of code'

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.

0

I'm gonna have to restructure the whole script I'm afraid. But now I know how to do it. :)

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