Hey there,
I am currently developing a game and are having trouble with a script.
The script should check a value until it hits a certain number.
Here is the script:
while true do
if heatValue.Value >= 10 then -- Set to 10 due to testing
print("Generators overheating")
Alarm.Motor.alarm:Play()
end
end
Nothing is being printed and the alarm sound doesn’t play.
Thanks for the assistance!
6 Likes
Is this the only loop in your script, if you have others it may be stopping the script further up.
Also i dont advice any loops without waits
1 Like
acuaro
(acuaro)
July 23, 2021, 1:01am
#3
If it’s a Value, there is a handy event called Changed
, just do
heatValue.Changed:Connect(function()
if heatValue.Value >= 10 then
print("Generators overheating")
Alarm.Motor.alarm:Play()
end
end)
4 Likes
D0RYU
(nici)
July 23, 2021, 1:04am
#4
acuaro:
heatValue.Value.Changed
no make it
heatValue.Changed
Changed works with Instances!
6 Likes
acuaro
(acuaro)
July 23, 2021, 1:04am
#5
Whoops! Slight mistake, thanks for the catch
2 Likes
Well, first of all. Add a wait:
while wait(.01) do
if heatValue.Value >= 10 then -- Set to 10 due to testing
print("Generators overheating")
Alarm.Motor.alarm:Play()
end
end
Also, I don’t recommend using loops as it affects performance. Use a Changed function for this.
3 Likes
Keleindor
(Keleindor)
July 23, 2021, 1:08am
#9
acuaro and D0RYU basically spelled it out, but if i can throw my two cents in, while true is generally a bad idea under any circumstances, because typically it’s more wasteful than other alternatives.
Also, without any waits or sections that yield, the code just runs as fast as it can, bringing any hardware it’s running on to its knees.
just my 2 sentences of unsolicited advice good luck on your game!
4 Likes
Fusionet
(Fusionet)
July 23, 2021, 1:08am
#10
What’s the full code look like? You’re not increasing the heat in this.
1 Like
Thanks to you and everyone else for the help!
There is another script that is increasing the value
1 Like