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

How to fix error in triggering a script when a intValue hits above a certain number?

I've been developing a reactor core game, and I have a temperature system used with intValue, I've tried to trigger a script for a meltdown when the temp value reaches 6500, but it doesn't trigger, what is the error I made?

if game.Workspace.Temp >= 6500 then
	script.Parent.Meltdown.Disabled = false
end

I've also tried using while true do, but it didn't help.

2 answers

✓ Accepted answer

You are probably getting error that you are trying to compare number and Instance, if [Temp] is an "IntValue", you need to get it's value by indexing it with [.Value]:

if workspace.Temp.Value >= 6500 then
	script.Parent.Meltdown.Disabled = false
end

This however as you know would only check it once, you could use the while loop as you did however it's not efficient, GetPropertyChangedSignal will return a signal which will fire when property of the Instance changes.

local Meltdown = script.Parent.Meltdown
local Temp = workspace.Temp

local function OnValueChangedAsync()
	if Temp.Value >= 6500 then
		if Meltdown.Disabled then
			Meltdown.Disabled = false
		end
	end
end

Temp:GetPropertyChangedSignal("Value"):Connect(OnValueChangedAsync)

I also added a check that will check if [Meltdown] is not disabled, this is not neccessary but prevents changing variable's value to same value, that would not cause an issue but yes.

4 comments

0

It gives in the output: "attempt to call a nil value" in red.

0

It must be coming from other scripts you have, not from this one.

0

is "Disabled" the script property or a BoolValue?

0

Oh yeah, thank you :) it worked! Thank you very much!

game.Workspace.Temp is the userdata, which is your IntValue in this case. The problem is that you're comparing said userdata to 6500, which is a number. You should be getting an error telling you exactly this, if you bothered to look at the output of your script. IntValues have a property called Value, which refers to the value assigned to the value Instance. In the case of an IntValue, the value assigned must be a 64-bit integer no greater than 9.22e+18 and no less than 9.22e-18. (Being an integer, of course, it can't be a floating point number.)

In simple words, use the Value property of your IntValue.

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