Value not being removed from the table

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


1 Like

This isn’t the correct usage. table.remove’s second parameter should be the index to remove, instead of the value.

You can either use string.find(Announceds, String) in place of string, or, as you already assigned the index to a variable, you can instead just do:

table.remove(Announced, AnnouncedValue)

When the AnnouncementValue was actually named String, i forgot to change It. Even when the named was String that was,t the problem. thanks for informing me, This might be the solution. I wiill test This solution later. And i Will Mark as asnwer If It is

No, it didn,t solved the problem of removing the value from the table, but atleast you corrected me of a typo, thank you. i updated the forum

i don,t know how but i found the solution

i was trying to find the solution by myself while i get no asnwers

and i think what solved is take the function off the while loop (basically), and makes a few tweaks to works off the while loop

it ended up like this:

	local function AnnounceTemperature(State, HighTempAnnouncerId, LowTempAnnouncerId)
		if table.find(Executeds, State) and not table.find(Announceds, State) then
			if (TemperatureValue.Value >= BadTemperatures[State].High) then
				AnnouncerScript.AnnounceBySoundId(HighTempAnnouncerId)
			elseif (TemperatureValue.Value <= BadTemperatures[State].Low) then
				AnnouncerScript.AnnounceBySoundId(LowTempAnnouncerId)
			end

			table.insert(Announceds, State)
		end
	end

	local function RemoveAnnouncementType(AnnouncementType)
		local AnnouncedValue = table.find(Announceds, AnnouncementType)

		if AnnouncedValue then
			table.remove(Announceds, AnnouncedValue)
		end
	end

i don,t know how to take the function off the loop made the script works, but it did.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.