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

How can I make a core temperature using values?

Im making a core as a personal project to maybe learn some things. Ive been scripting for a while but never got how to add and subtract values using a script.

I need to add and subtract the values to get the temperature to rise and decrease. I have multiple machines that will effect the temperature. Once the core reaches 2000 degrees it will melt down and -2000 degrees will freeze down.

How can I set this up? Thanks for the help!

2 answers

✓ Accepted answer

Might look something like this to startout:

function Meltdown()
--whatever happens in here
end
function Freezedown()
--whatever happens in here
end
local MeltdownPoint = 2000
local FreezedownPoint = 2000
local updateRate = .25
local temperature = 0
local temperatureDelta = 0 -- basically the change in temperature
while true do
	wait(updateRate)
	temperature = temperature + temperatureDelta
	if temperature >= MeltdownPoint then
		Meltdown()
	elseif
		Freezedown()
	end
end

If you wanted to make the temperature change random it might look something like this:

function Meltdown()
--whatever happens in here
end
function Freezedown()
--whatever happens in here
end
local MeltdownPoint = 2000
local FreezedownPoint = 2000
local updateRate = .25
local temperature = 0
local temperatureDelta = 0 -- basically the change in temperature
while true do
	wait(updateRate)
	temperatureDelta = temperatureDelta + (math.random(-3,3)) -- can be any range you want
	temperature = temperature + temperatureDelta
	if temperature >= MeltdownPoint then
		Meltdown()
	elseif
		Freezedown()
	end
end

if this was a server script and based on player input you could have a remote events that the client fire to change the temperature delta

function Meltdown()
--whatever happens in here
end
function Freezedown()
--whatever happens in here
end
local MeltdownPoint = 2000
local FreezedownPoint = 2000
local updateRate = .25
local temperature = 0
local temperatureDelta = 0 -- basically the change in temperature
while true do
	wait(updateRate)
	temperature = temperature + temperatureDelta
	if temperature >= MeltdownPoint then
		Meltdown()
	elseif
		Freezedown()
	end
end
tempDeltaUpEvent.OnServerEvent:Connect(function() 
temperatureDelta = temperatureDelta + 1
end)
tempDeltaDownEvent.OnServerEvent:Connect(function() 
temperatureDelta = temperatureDelta -1
end)

I assume you are using either an IntValue or a NumberValue. If you need to use decimal points use NumberValue if you don't; use IntValue. To change the values of these, access it's Value property by.

local IntValue = game.Workspace.IntValue

IntValue.Value = 1

--or

local NumberValue = game.Workspace.NumberValue

NumberValue.Value = 1

This sets the value to 0. You mentioned having multiple machines affecting the overall temperature of the core, I recommend having each machine have their own IntValue/NumberValue then add them together to get the core temperature so that you don't have to deal with multithreading. For this, you need to have a folder to hold a value for each machine temperature then iterate over them using «GetChildren()» to get the final result to display.

You might also want to use the «Changed()» event of the core Int/Number Value to check if it reached either -2000 or 2000 then do something if it does

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