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.
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
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
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.
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.