Hello, so I recently just finished my Meltdown Detector script what I am making for my Nuclear Powerplant for my project at school. But recently found out it glitches really bad. Please take a look at my script:
PS: It is huge.
There is no errors but it glitches out like this: https://www.youtube.com/watch?v=hoLFW7123vs
Glitches: There is suppost to be more fire on the screen More emergencylights should spin The screen should not keep on switching. I think I know why this is happening but I have no experience of return end. The lights should change to orange or red when mode is switched.
currentTemp=game.Workspace:WaitForChild("TemperatureValue") AlarmMinorS=game.Workspace.AlarmMinor AlarmMajorS=game.Workspace.AlarmMajor MainframeStatus=game.Workspace.MainframeStatus.SurfaceGui.TextLabel local firethree = workspace.Mainframe_Status_Fire_Parts:GetChildren() local mainframelights = workspace.MainframeLights:GetChildren() local emergencylightson2 = workspace.EmergencyLights:GetChildren() local lightson2 = workspace.EnteranceLights:GetChildren() local lightsonfloor2 = workspace.EnteranceFloorLights:GetChildren() local emergencylightson = workspace.EmergencyLights:GetChildren() local fireone = workspace.Mainframe_Status_Fire_Parts:GetChildren() local mainframelightstwo = workspace.MainframeLights:GetChildren() local lightsoff = workspace.EnteranceLights:GetChildren() local lightsofffloor = workspace.EnteranceFloorLights:GetChildren() local mainframelightsthree = workspace.MainframeLights:GetChildren() local emergencylightsoff = workspace.EmergencyLights:GetChildren() local lightson = workspace.EnteranceLights:GetChildren() local lightsonfloor = workspace.EnteranceFloorLights:GetChildren() function alarmMinor() if currentTemp.Value >= 700 then AlarmMinorS:Play() AlarmMajorS:Stop() wait(3) MainframeStatus.Text = "LavaBlast://Core_Status/Issue" MainframeStatus.TextColor3 = Color3.new(255, 85, 0) wait(3) for i = 1, #firethree do firethree[i].Fire.Enabled = false wait(0.5) for i = 1, #mainframelights do mainframelights[i].Light.PointLight.Color = Color3.new(1, 170/255, 0) mainframelights[i].Light.PointLight.Color = Color3.new(255, 170/255, 0) mainframelights[i].Light.BrickColor = BrickColor.new("Orange") wait(0.5) for i = 1, #emergencylightson2 do emergencylightson2[i].Toggle.Value = false wait(0.5) for i = 1, #lightson2 do lightson2[i].Part.SpotLight.Enabled = true wait(0.5) for i = 1, #lightsonfloor2 do lightsonfloor2[i].Light.PointLight.Enabled = true wait(0.5) end end end end end end end function alarmMajor() if currentTemp.Value >= 1000 then AlarmMajorS:Play() AlarmMinorS:Stop() MainframeStatus.Text = "LavaBlast://Core_Status/Major" MainframeStatus.TextColor3 = Color3.new(255, 0, 0) wait(3) for i = 1, #emergencylightson do emergencylightson[i].Toggle.Value = true wait(0.5) for i = 1, #fireone do fireone[i].Fire.Enabled = true wait(0.5) for i = 1, #mainframelightstwo do mainframelightstwo[i].Light.PointLight.Color = Color3.new(1, 0, 0) mainframelightstwo[i].Light.PointLight.Color = Color3.new(1, 0, 0) mainframelightstwo[i].Light.BrickColor = BrickColor.new("Red") wait(0.5) for i = 1, #lightsoff do lightsoff[i].Part.SpotLight.Enabled = false wait(0.5) for i = 1, #lightsofffloor do lightsofffloor[i].Light.PointLight.Enabled = false wait(0.5) end end end end end end end function normalTemperature() if currentTemp.Value < 699 then AlarmMinorS:Stop() AlarmMajorS:Stop() wait(3) MainframeStatus.Text = "LavaBlast://Core_Status/Stable" MainframeStatus.TextColor3 = Color3.new(255, 255, 255) for i = 1, #fireone do fireone[i].Fire.Enabled = false wait(0.5) for i = 1, #mainframelightsthree do mainframelightsthree[i].Light.PointLight.Color = Color3.new(255, 255, 255) mainframelightsthree[i].Light.PointLight.Color = Color3.new(255, 255, 255) mainframelightsthree[i].Light.BrickColor = BrickColor.new("White") wait(0.5) for i = 1, #emergencylightsoff do emergencylightsoff[i].Toggle.Value = false wait(0.5) for i = 1, #lightson do lightson[i].Part.SpotLight.Enabled = true wait(0.5) for i = 1, #lightsonfloor do lightsonfloor[i].Light.PointLight.Enabled = true wait(0.5) end end end end end end end while true do wait(5) print "lol" spawn (alarmMinor) spawn (alarmMajor) spawn (normalTemperature) end
This is a little inefficient.
Here are some of the errors I found:
For loop ends positioned improperly (loops inside loops)
AlarmMinor and AlarmMajor functions both fire when above 1000 (no upper restriction on Alarm Minor)
What I would do is use the Changed event of the NumberValue object to check the temperature every time it is changed. Then you won't have to wait 5 seconds to update.
currentTemp=game.Workspace:WaitForChild("TemperatureValue") AlarmMinorS=game.Workspace.AlarmMinor AlarmMajorS=game.Workspace.AlarmMajor MainframeStatus=game.Workspace.MainframeStatus.SurfaceGui.TextLabel local firethree = workspace.Mainframe_Status_Fire_Parts:GetChildren() local mainframelights = workspace.MainframeLights:GetChildren() local emergencylightson2 = workspace.EmergencyLights:GetChildren() local lightson2 = workspace.EnteranceLights:GetChildren() local lightsonfloor2 = workspace.EnteranceFloorLights:GetChildren() local emergencylightson = workspace.EmergencyLights:GetChildren() local fireone = workspace.Mainframe_Status_Fire_Parts:GetChildren() local mainframelightstwo = workspace.MainframeLights:GetChildren() local lightsoff = workspace.EnteranceLights:GetChildren() local lightsofffloor = workspace.EnteranceFloorLights:GetChildren() local mainframelightsthree = workspace.MainframeLights:GetChildren() local emergencylightsoff = workspace.EmergencyLights:GetChildren() local lightson = workspace.EnteranceLights:GetChildren() local lightsonfloor = workspace.EnteranceFloorLights:GetChildren() local state = nil -- current alarm level currentTemp.Changed:connect(function() -- Changed event if currentTemp.Value >= 700 and currentTemp.Value < 1000 and state ~= 'MinorAlarm' then -- Between 700 and 1000 and not already fired state = 'MinorAlarm' -- Sets alarm level to Minor AlarmMinorS:Play() AlarmMajorS:Stop() wait(3) MainframeStatus.Text = "LavaBlast://Core_Status/Issue" MainframeStatus.TextColor3 = Color3.new(255, 85, 0) wait(3) for i = 1, #firethree do firethree[i].Fire.Enabled = false wait(0.5) end for i = 1, #mainframelights do mainframelights[i].Light.PointLight.Color = Color3.new(1, 170/255, 0) mainframelights[i].Light.PointLight.Color = Color3.new(255, 170/255, 0) mainframelights[i].Light.BrickColor = BrickColor.new("Orange") wait(0.5) end for i = 1, #emergencylightson2 do emergencylightson2[i].Toggle.Value = false wait(0.5) end for i = 1, #lightson2 do lightson2[i].Part.SpotLight.Enabled = true wait(0.5) end for i = 1, #lightsonfloor2 do lightsonfloor2[i].Light.PointLight.Enabled = true wait(0.5) end elseif currentTemp.Value >= 1000 and state ~= 'MajorAlarm' then -- Above 1000 and not already fired state = 'MajorAlarm' -- Sets Alarm Level to Major AlarmMajorS:Play() AlarmMinorS:Stop() MainframeStatus.Text = "LavaBlast://Core_Status/Major" MainframeStatus.TextColor3 = Color3.new(255, 0, 0) wait(3) for i = 1, #emergencylightson do emergencylightson[i].Toggle.Value = true wait(0.5) end for i = 1, #fireone do fireone[i].Fire.Enabled = true wait(0.5) end for i = 1, #mainframelightstwo do mainframelightstwo[i].Light.PointLight.Color = Color3.new(1, 0, 0) mainframelightstwo[i].Light.PointLight.Color = Color3.new(1, 0, 0) mainframelightstwo[i].Light.BrickColor = BrickColor.new("Red") wait(0.5) end for i = 1, #lightsoff do lightsoff[i].Part.SpotLight.Enabled = false wait(0.5) end for i = 1, #lightsofffloor do lightsofffloor[i].Light.PointLight.Enabled = false wait(0.5) end elseif currentTemp.Value < 700 and state ~= 'NoAlarm' then -- Below 700 and not already fired state = 'NoAlarm' AlarmMinorS:Stop() AlarmMajorS:Stop() wait(3) MainframeStatus.Text = "LavaBlast://Core_Status/Stable" MainframeStatus.TextColor3 = Color3.new(255, 255, 255) for i = 1, #fireone do fireone[i].Fire.Enabled = false wait(0.5) end for i = 1, #mainframelightsthree do mainframelightsthree[i].Light.PointLight.Color = Color3.new(255, 255, 255) mainframelightsthree[i].Light.PointLight.Color = Color3.new(255, 255, 255) mainframelightsthree[i].Light.BrickColor = BrickColor.new("White") wait(0.5) end for i = 1, #emergencylightsoff do emergencylightsoff[i].Toggle.Value = false wait(0.5) end for i = 1, #lightson do lightson[i].Part.SpotLight.Enabled = true wait(0.5) end for i = 1, #lightsonfloor do lightsonfloor[i].Light.PointLight.Enabled = true wait(0.5) end end end)