i made a part of a script that an announcer says something when the temperature reaches a certain temperature. and when the temperature goes down (less than the certain value), when it reaches again, the announcer announces again, and over…
the problem is, the table that indicates if the announcer said an specific thing or not (announced) is not being removed, for some reason, because of that, the announcer doesn,t say the same things again
i printed the table ‘announced’, when the temperature goes down and gets less than the reached, the value stays there
i tried to add a print to the if statement of the table value removing function (RemoveAnnouncementType) and somehow printed
i tried to change the value that gets the position of the value in ‘announced’ (AnnouncedValue) to the position that got from ‘announced’ after the value got removed and print it. suprinsingly it prints nil
i also tried to use String[] = nil instead of table.remove() it didn,t solved neither
i tried to find a typo, or something else wrong in the code by viewing the code twice, but i didn,t found neither of them
here’s the function, (and the separated lines that will indicate where is the part of the announcer script. i will put ‘included’ above some of the lines to detect what is the part of the announcer script and what isn,t)
local Ts = game.TweenService
local EventsModule = require(game.ServerScriptService:WaitForChild("DisastersModule",2))
local AnnouncerScript = require(game.ServerScriptService:WaitForChild("AnnouncerScript",2))
local Core = workspace.CoreChamber:WaitForChild("Core",2)
local CoreSound = Core:WaitForChild("Core").CoreAmbience
local CoreSettings = game.ServerStorage:WaitForChild("CoreSettings",2)
local CanChange = CoreSettings:WaitForChild("CanChangeTemperature",2)
local Temperature = CoreSettings:WaitForChild("CoreTemperature",2)
local HPS = CoreSettings:WaitForChild("HeatPerSecond",2)
local AlarmPanel = workspace:WaitForChild("ControlRoom",2).ControlPanel.Controls:WaitForChild("AlarmsPanel",2).Alarms
local MaxTemp = 140000
local MinTemp = -50000
local function StartUpdating()
local function UpdateTemperature()
local Goal = Temperature.Value + HPS.Value
local TsInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local Update = Ts:Create(Temperature, TsInfo, {Value = Goal})
local UpdateSound = Ts:Create(CoreSound, TsInfo, {PlaybackSpeed = math.clamp((Goal / MaxTemp) + 0.6, 0.5, 1.5)})
UpdateSound:Play()
if CanChange.Value ~= false then
Update:Play()
end
wait(TsInfo.Time)
return Temperature.Value
end
local Executeds = {}
Included
local Announceds = {}
while Core and CanChange.Value == true do
local Temperature = UpdateTemperature()
Included
local function RemoveAnnouncementType(AnnouncementType)
local AnnouncedValue = table.find(Announceds, AnnouncementType)
if AnnouncedValue then
table.remove(Announceds, AnnouncedValue)
end
end
local FindStats =
{
["Unstable"] = table.find(Executeds, "Unstable"),
["Danger"] = table.find(Executeds, "Danger"),
["Critical"] = table.find(Executeds, "Critical"),
["MeltdownImminet"] = table.find(Executeds, "MeltdownImminet"),
["FreezedownImminet"] = table.find(Executeds, "FreezedownImminet")
}
local Alarms = {
["Unstable"] = AlarmPanel:WaitForChild("Unstable",2),
["Danger"] = AlarmPanel:WaitForChild("Danger",2),
["Critical"] = AlarmPanel:WaitForChild("Critical",2),
["MeltdownImminet"] = AlarmPanel:WaitForChild("MeltdownImminet",2),
["FreezedownImminet"] = AlarmPanel:WaitForChild("FreezedownImminet",2)
}
Included
if (Temperature >= 60000) or (Temperature <= 20000) then
Alarms.Unstable.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Unstable then
table.insert(Executeds, "Unstable")
end
else
Alarms.Unstable.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Unstable then
table.remove(Executeds, "Unstable")
RemoveAnnouncementType("Unstable")
end
end
if (Temperature >= 80000) or (Temperature <= 10000) then
Alarms.Danger.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Danger then
table.insert(Executeds, "Danger")
end
else
Alarms.Danger.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Danger then
table.remove(Executeds, FindStats.Danger)
RemoveAnnouncementType("Danger")
end
end
if (Temperature >= 100000) or (Temperature <= 0) then
Alarms.Critical.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Critical then
table.insert(Executeds, "Critical")
end
else
Alarms.Critical.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Critical then
table.remove(Executeds, FindStats.Critical)
RemoveAnnouncementType("Critical")
end
end
if (Temperature >= 120000) then
Alarms.MeltdownImminet.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.MeltdownImminet then
table.insert(Executeds, "MeltdownImminet")
end
elseif (Temperature <= -10000) then
Alarms.FreezedownImminet.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.FreezedownImminet then
table.insert(Executeds, "FreezedownImminet")
end
else
Alarms.MeltdownImminet.Configuration:WaitForChild("Enabled").Value = false
Alarms.FreezedownImminet.Configuration:WaitForChild("Enabled").Value = false
if FindStats.MeltdownImminet then
table.remove(Executeds, FindStats.MeltdownImminet)
RemoveAnnouncementType("MeltdownImminet")
end
if FindStats.FreezedownImminet then
table.remove(Executeds, FindStats.FreezedownImminet)
RemoveAnnouncementType("FreezedownImminet")
end
end
if (Temperature >= MaxTemp) then
EventsModule.Meltdown()
elseif (Temperature <= MinTemp) then
EventsModule.Freezedown()
end
Included
if FindStats.Unstable and not table.find(Announceds, "Unstable") then
table.insert(Announceds, "Unstable")
end
if FindStats.Danger and not table.find(Announceds, "Danger") then
local HighTemp = 80000
local LowTemp = 10000
local HighTempAnnouncerId = "rbxassetid://16126874179"
local LowTempAnnouncerId = "rbxassetid://16126904764"
if (Temperature >= HighTemp) then
AnnouncerScript.AnnounceBySoundId(HighTempAnnouncerId)
elseif (Temperature <= LowTemp) then
AnnouncerScript.AnnounceBySoundId(HighTempAnnouncerId)
end
table.insert(Announceds, "Danger")
end
if FindStats.Critical and not table.find(Announceds, "Critical") then
--AnnounceScriptHere
table.insert(Announceds, "Critical")
end
end
end
- here is the same code but everything together, so you can test it
local Ts = game.TweenService
local EventsModule = require(game.ServerScriptService:WaitForChild("DisastersModule",2))
local AnnouncerScript = require(game.ServerScriptService:WaitForChild("AnnouncerScript",2))
local Core = workspace.CoreChamber:WaitForChild("Core",2)
local CoreSound = Core:WaitForChild("Core").CoreAmbience
local CoreSettings = game.ServerStorage:WaitForChild("CoreSettings",2)
local CanChange = CoreSettings:WaitForChild("CanChangeTemperature",2)
local Temperature = CoreSettings:WaitForChild("CoreTemperature",2)
local HPS = CoreSettings:WaitForChild("HeatPerSecond",2)
local AlarmPanel = workspace:WaitForChild("ControlRoom",2).ControlPanel.Controls:WaitForChild("AlarmsPanel",2).Alarms
local MaxTemp = 140000
local MinTemp = -50000
local function StartUpdating()
local function UpdateTemperature()
local Goal = Temperature.Value + HPS.Value
local TsInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local Update = Ts:Create(Temperature, TsInfo, {Value = Goal})
local UpdateSound = Ts:Create(CoreSound, TsInfo, {PlaybackSpeed = math.clamp((Goal / MaxTemp) + 0.6, 0.5, 1.5)})
UpdateSound:Play()
if CanChange.Value ~= false then
Update:Play()
end
wait(TsInfo.Time)
return Temperature.Value
end
local Executeds = {}
local Announceds = {}
while Core and CanChange.Value == true do
local Temperature = UpdateTemperature()
local function RemoveAnnouncementType(AnnouncementType)
local AnnouncedValue = table.find(Announceds, AnnouncementType)
if AnnouncedValue then
table.remove(Announceds, AnnouncementType)
end
end
local FindStats =
{
["Unstable"] = table.find(Executeds, "Unstable"),
["Danger"] = table.find(Executeds, "Danger"),
["Critical"] = table.find(Executeds, "Critical"),
["MeltdownImminet"] = table.find(Executeds, "MeltdownImminet"),
["FreezedownImminet"] = table.find(Executeds, "FreezedownImminet")
}
local Alarms = {
["Unstable"] = AlarmPanel:WaitForChild("Unstable",2),
["Danger"] = AlarmPanel:WaitForChild("Danger",2),
["Critical"] = AlarmPanel:WaitForChild("Critical",2),
["MeltdownImminet"] = AlarmPanel:WaitForChild("MeltdownImminet",2),
["FreezedownImminet"] = AlarmPanel:WaitForChild("FreezedownImminet",2)
}
if (Temperature >= 60000) or (Temperature <= 20000) then
Alarms.Unstable.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Unstable then
table.insert(Executeds, "Unstable")
end
else
Alarms.Unstable.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Unstable then
table.remove(Executeds, "Unstable")
RemoveAnnouncementType("Unstable")
end
end
if (Temperature >= 80000) or (Temperature <= 10000) then
Alarms.Danger.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Danger then
table.insert(Executeds, "Danger")
end
else
Alarms.Danger.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Danger then
table.remove(Executeds, FindStats.Danger)
RemoveAnnouncementType("Danger")
end
end
if (Temperature >= 100000) or (Temperature <= 0) then
Alarms.Critical.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.Critical then
table.insert(Executeds, "Critical")
end
else
Alarms.Critical.Configuration:WaitForChild("Enabled").Value = false
if FindStats.Critical then
table.remove(Executeds, FindStats.Critical)
RemoveAnnouncementType("Critical")
end
end
if (Temperature >= 120000) then
Alarms.MeltdownImminet.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.MeltdownImminet then
table.insert(Executeds, "MeltdownImminet")
end
elseif (Temperature <= -10000) then
Alarms.FreezedownImminet.Configuration:WaitForChild("Enabled").Value = true
if not FindStats.FreezedownImminet then
table.insert(Executeds, "FreezedownImminet")
end
else
Alarms.MeltdownImminet.Configuration:WaitForChild("Enabled").Value = false
Alarms.FreezedownImminet.Configuration:WaitForChild("Enabled").Value = false
if FindStats.MeltdownImminet then
table.remove(Executeds, FindStats.MeltdownImminet)
RemoveAnnouncementType("MeltdownImminet")
end
if FindStats.FreezedownImminet then
table.remove(Executeds, FindStats.FreezedownImminet)
RemoveAnnouncementType("FreezedownImminet")
end
end
if (Temperature >= MaxTemp) then
EventsModule.Meltdown()
elseif (Temperature <= MinTemp) then
EventsModule.Freezedown()
end
if FindStats.Unstable and not table.find(Announceds, "Unstable") then
table.insert(Announceds, "Unstable")
end
if FindStats.Danger and not table.find(Announceds, "Danger") then
local HighTemp = 80000
local LowTemp = 10000
local HighTempAnnouncerId = "rbxassetid://16126874179"
local LowTempAnnouncerId = "rbxassetid://16126904764"
if (Temperature >= HighTemp) then
AnnouncerScript.AnnounceBySoundId(HighTempAnnouncerId)
elseif (Temperature <= LowTemp) then
AnnouncerScript.AnnounceBySoundId(HighTempAnnouncerId)
end
table.insert(Announceds, "Danger")
end
if FindStats.Critical and not table.find(Announceds, "Critical") then
--AnnounceScriptHere
table.insert(Announceds, "Critical")
end
end
end