local player = game.Players.LocalPlayer
local lightPanels = workspace:FindFirstChild("LightPanels")
local panels = lightPanels:FindFirstChild("Panels"):GetChildren()
panelsTable = {}
function checkPanels()
for i, panel in pairs(panels) do
if panel.Material == Enum.Material.SmoothPlastic and not panelsTable[panel.Name] then
table.insert(panelsTable,panel.Name)
end
end
print(#panelsTable)
print(#panels)
if #panelsTable == #panels then
print("success")
end
end
game.ReplicatedStorage:FindFirstChild("PanelEvent").OnClientEvent:Connect(function(panel)
local char = player.Character
if char then
local pingSound = char:FindFirstChild("PingSound")
pingSound:Play()
panel.Material = Enum.Material.SmoothPlastic
end
end)
while wait(.5) do
checkPanels()
end
I am essentially trying to make a system whereby you touch a panel, then that panel changes material to SmoothPlastic and adds the panel in question to panelsTable (in function checkPanels).
However, everytime the function runs, the same panels keep getting added to the table. It seems as though 'and not panelsTable[panel.Name]' is not working? For example I touch 1 panel. everytime #panelsTable is printed every 0.5 seconds, that same panel is being added to the table, despite checking that it's not already in the table before adding it.
Would appreciate assistance

1 comment
legend