[SOLVED] .Changed does not work for my script

So I’ve been trying to make this reactor core game for my friends to play, but when I’m trying to detect when the temp has gone over a certain threshold, .Changed simply doesn’t work and no message gets printed in my script below.

local temp1 = script.temp

temp1.Changed:Connect(function()

print("change detected")

script.temp in this instance is a intvalue, I’m not that good at scripting so I probably just made a very stupid mistake which I’m not noticing right now.

1 Like

@General_curve Try This:

temp1.Changed:Connect(function(Changed)
if Changed then
print("Change Detected")
end
end)

im not good at scripting either but i think i can help solve this

1 Like

it didnt print anything when I ran it

Is the Number changing when you run the script?

Yes the number is changing when I am running the script.

1 Like

show me the entire script, maybe you have an error

temp = script.temp.Value
tempchange = 1
changerate = 0.1
scram = false
canscram = true
game.ServerScriptService.ValueChanged.Event:Connect(function(value)
	print("received!")
	changerate = changerate + value
end)

game.ServerScriptService.Scram.Event:Connect(function()
	if canscram == true then
		script.Alarm:Play()
		scram = true	
		canscram = false
		wait(5)
		if temp >= 500 then
			changerate = 0.01
		end
		if temp >= 1000 then
			changerate = 0.005
		end
		repeat
			temp = temp - tempchange	
			script.Parent.Text = temp
			wait(changerate)
		until temp == 0
		scram = false
		end
end)

local temp1 = script.temp
temp1.Changed:Connect(function(Changed)
	if Changed then
		print("change detected")
		if temp >= 2000 then
			script.Alarm:Play()
		end
	end
end)
repeat
	temp = temp + tempchange
	script.Parent.Text = temp
	wait(changerate)
until temp == 15000 or scram == true


Temp1 doesnt have a value, unlike temp

you appear to have forgotten to add script.Temp.Value

putting .value at the end won’t work and results in a error when I tested it

This is a server script, correct? If not, local scripts don’t work in workspace or other places that are not related to the player. Also, is this the whole script? If it isn’t, make sure that there is nothing infinitely yielding the rest of the script. Other than that, try using :GetPropertyChangedSignal

local temp1 = script.temp

temp1:GetPropertyChangedSignal:Connect(function()
    print("Changed")
end)

Edit: Looking at the whole script, the problem is that you are saving the value of temp as a number and not actually directly changing the value.

temp = script.temp
tempchange = 1
changerate = 0.1
scram = false
canscram = true
game.ServerScriptService.ValueChanged.Event:Connect(function(value)
	print("received!")
	changerate = changerate + value
end)

game.ServerScriptService.Scram.Event:Connect(function()
	if canscram == true then
		script.Alarm:Play()
		scram = true	
		canscram = false
		wait(5)
		if temp.Value >= 500 then
			changerate = 0.01
		end
		if temp.Value >= 1000 then
			changerate = 0.005
		end
		repeat
			temp.Value = temp.Value - tempchange	
			script.Parent.Text = temp.Value
			wait(changerate)
		until temp.Value == 0
		scram = false
		end
end)

temp.Changed:Connect(function(Changed)
	if Changed then
		print("change detected")
		if temp.Value >= 2000 then
			script.Alarm:Play()
		end
	end
end)

repeat
	temp.Value += tempchange
	script.Parent.Text = temp.Value
	wait(changerate)
until temp.Value == 15000 or scram == true

here i’ll try it again and see what happens

whats is the error you are getting?

an easy solution:

since temp = script.Temp.Value

change Temp1 to make it say this since they are the same value

temp1 = temp

this is probably why you are getting no response from the Output
try both

1 Like

The only problem with this script is the fact you are saving the value as a variable and changing that, which doesn’t effect the actual instance. I provided the solution here

2 Likes

is it

temp = script.temp.Value 

or just

temp = script.temp
1 Like

It should just be script.temp. Again, the problem was that he was saving the first value of the temperature and changing the variable that was saved, and not the actual value.

1 Like

The script appears to be checking the value of the Int,
it might be

script.temp.Value

Since it gets the Value of whats inside the IntValue

the script appears to check if the value is greater than or equal to a certain value

1 Like

Again, the problem is that it isn’t changing the value of the int value, which makes it not able to detect the change.
Also, my previous script forgot to add the .Value when checking the value of it, so I fixed that.

yup, thank you, I tested this and tried it and it works, thanks

I told you that you forgot it, and you said it didnt need it

I forgot to put the .Value when checking the value.