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

Can you find anything wrong with this snippet of code? Function not executing correctly.

TmpChng (line 63.) is supposed to be responsible for the changing of the temperature either up or down based on the value "CoolantActive" being true or false.

So far it works right, when it lowers to 300 it stops which is as low as I want it to go, but when its going up is the problem.

It keeps getting stuck at 499.

Any idea why?

local Coolant = script.Parent.GUIS.Coolant.SurfaceGui:WaitForChild("TextBox")
local Status = script.Parent.GUIS.Status.SurfaceGui:WaitForChild("TextBox")
local Temp = script.Parent.GUIS.Temp.SurfaceGui:WaitForChild("TextBox")
local TempValue = script.Parent.VALUES:WaitForChild("Temp")
local Meltdown = script.Parent.VALUES:WaitForChild("MeltdownStatus")
local SelfDestruct = script.Parent.VALUES:WaitForChild("SelfDestruct")
local CoolantActive = script.Parent.VALUES:WaitForChild("CoolantActive")


function Melt()
	Coolant.Text = "MELTDOWN"
	Coolant.TextColor3 = Color3.fromRGB(255,0,0)
	Status.Text = "MELTDOWN"
	Status.TextColor3 = Color3.fromRGB(255,0,0)
	Temp.Text = "MELTDOWN"
	Temp.TextColor3 = Color3.fromRGB(255,0,0)
end

function MeltImminent()
	Coolant.Text = "MELTDOWN IMMINENT"
	Coolant.TextColor3 = Color3.fromRGB(255,0,0)
	Status.Text = "MELTDOWN IMMINENT"
	Status.TextColor3 = Color3.fromRGB(255,0,0)
	Temp.TextColor3 = Color3.fromRGB(255,0,0)
end

function OvHeat()
	Status.Text = "OVERHEAT"
	Status.TextColor3 = Color3.fromRGB(198,150,55)
	Temp.TextColor3 = Color3.fromRGB(198,150,55)
end

function PwrSts()
	Status.Text = "Generating Power"
	Status.TextColor3 = Color3.fromRGB(69,255,137)
end

function Destruct()
	Coolant.Text = "SELF DESTRUCT"
	Coolant.TextColor3 = Color3.fromRGB(255,0,0)
	Status.Text = "SELF DESTRUCT"
	Status.TextColor3 = Color3.fromRGB(255,0,0)
	Temp.Text = "SELF DESTRUCT"
	Temp.TextColor3 = Color3.fromRGB(255,0,0)
end

function CoolantSts()
	if CoolantActive.Value == true then
		Coolant.Text = "Coolant Active"
		Coolant.TextColor3 = Color3.fromRGB(69,255,137)
	elseif CoolantActive.Value == false then
		Coolant.Text = "Coolant Disabled"
		Coolant.TextColor3 = Color3.fromRGB(255,0,0)
	end
end

function UpdTemp()
	Temp.Text = TempValue.Value
	Temp.TextColor3 = Color3.fromRGB(69,255,137)
end


function TmpChng()
	if CoolantActive.Value == true and TempValue.Value >= 301 then
	wait(.2)
	TempValue.Value = TempValue.Value - 1
	elseif CoolantActive.Value == false and TempValue.Value >= 301 then
	wait(.2)
	TempValue.Value = TempValue.Value + 1
	end
end

while true do
	if Meltdown.Value == false and SelfDestruct.Value == false and TempValue.Value <= 499 then
		wait()
		TmpChng()
		UpdTemp()
		PwrSts()
		CoolantSts()
	elseif Meltdown.Value == false and SelfDestruct.Value == false and TempValue.Value >= 500 and TempValue.Value <= 799 then
		wait()
TmpChng()
		OvHeat()
		CoolantSts()
	elseif Meltdown.Value == false and SelfDestruct.Value == false and TempValue.Value >= 800 and TempValue.Value <= 999 then
		wait()
		MeltImminent()
	elseif Meltdown.Value == false and SelfDestruct.Value == false and TempValue.Value >= 1000 then
		wait()
		Melt()
	end
end

1 answer

✓ Accepted answer

whats problematic about the function on line 63?

if tempValue.Value is higher than 499 u never call tempChng, so yes, it will be 'stuck' on 499

3 comments

0

tempChng is called again on line 82 for the line 80 elseif, that covers up to 799.

0

Aah hmm true. Sorry, I got fooled by indentation.. Also it would have been stuck at 500 not 499. Hows this instead: maybe its just that you don't call updTemp() when temp>=500, so that it works but you don't see it?

0

that still would make it read 500 though. as a side note I recommend writing <500 instead of <= 499 , because if your TempValue.Value contains something with decimals it would get stuck at 499. in fact the whole >500 bit is not needed in elseif unless u want it to stop between 499 and 500

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