How would I make this?

Hello, good afternoon and happy New Years. I am making a core game, where if the core temperature reaches a certain temperature it will explode. I have that part down, but I don’t know how I would make it so that if the players can cool down the core before it explodes, then the core won’t explode. Meaning that once the procedure for the core o explode happens, you can still stop it.

Can you show us what you have so far?

Okay, but beware the code will make your brain fry.

while task.wait() do
	if game.ReplicatedStorage.Values.Temp.Value >= 60000 then
		task.wait(6)
		for i,v in pairs(workspace.Explosion:GetChildren()) do
			v.Transparency = 0
			while task.wait() do 
				
				local angle1 = CFrame.Angles(0, 0.12, 0)
				
				local angle2 = CFrame.Angles(0, 0.2, 0)
				
				local angle3 = CFrame.Angles(0, 0.28, 0)
				
				for i = 0, 100 do
					v.CFrame *= angle1
				end
				
				for i = 0, 140 do
					v.CFrame *= angle2
				end
				
				for i = 0, 220 do
					v.CFrame *= angle3
				end
				
				
			end
		end
	end
end
while task.wait() do
	if game.ReplicatedStorage.Values.Temp.Value >= 60000 then
		local players = game:GetService("Players")

		task.wait(17)

		for i,c in pairs(players:GetChildren()) do
			c:Kick("The core exploded, gg. Better luck next time.")
		end
	end
end
while task.wait() do
	if game.ReplicatedStorage.Values.Temp.Value >= 60000 then
		script.Parent["Emergency Alert"]:Play()
		task.wait(11)
		script.Enabled = false
	end
end

local helpDetector = the cooling click detector
local coolingAmount = 5

helpDetector.MC:C(f()
     temp -= coolingAmount
end)

Something similar to above could do it pretty simply. (keep in mind i half coded, half text coded it)

It would be easier to see your current code so I could test with it.

If I were to make this I’d split this up into smaller problems.

1. Tracking temperature

You need to keep track of the current temperature as well as how it should change. To do this I’d add the attributes Temperature, Heating, Cooling to the core.

2. Changing the temperature

Now that the data is in place, it is time to start utilizing it. To start with, the increase in temperature should probably be Heating - Cooling, this means the code for updating the temperature should be:

local function getAttr(attrName: string): any -- Gets tedious to write
	return core:GetAttribute(attrName)
end

local function setAttr(attrName: string, value: any)

task.spawn(function()
	local refreshRate = 10 -- updates per second
	while task.wait(1/10) do
		local temp = getAttr("Temperature")
		local heating = getAttr("Heating")
		local cooling = getAttr("Cooling")
		setAttr("Temperature", temp + (heating - cooling)/refreshRate) -- Heating and Cooling is given in degrees/s, so account for refreshrate
	end
end)

3. Changing the cooling

Lets say you have some buttons to activate different coolant pumps, in that case you only need to trigger this function in order to update cooling:

function changeCooling(coolingDelta: number)
	setAttr("Cooling", getAttr("Cooling") + coolingDelta)
end

If you detect that a pump is activated, call changeCooling(10) if the pump increases the cooling power by 10, and changeCooling(-10) if you want to deactivate that pump.

4. Explosion

You can detect when the explosion should go off in two ways. Either add it into the while-loop described earlier, or do:

core:GetAttributeChangedSignal("Temperature"):Connect(function()
	if getAttr("Temperature") < EXPLOSION_THRESHOLD then return end -- No explosion if temp <= EXPLOSION_THRESHOLD
	-- Boom!

@MRG_GROUPHOLDER Updated the message now!

Code is in a reply above.

:+1:

Edit: Aside from this topic, does anyone know how to make a negative number? For example;

if blahblahblah == -100 then
 -- some code
end

The problem is that it doesn’t detect the negativity

If you do:

function checkSign()
	if num == 0 then
		print("Zero!")
	elseif num > 0 then
		print("Positive!")
	else
		print("Negative!")
	end
end

checkSign(10) -- Prints "Positive!"
checkSign(-10) -- Prints "Negative!"