I have this script and it updates GUI values basically but its firing functions when its not supposed to.
Heres the code and ill explain more. HEADS UP, this is just portions of the important code not all the code.
local ItemTable = {"Campfire", "Smelter", "StorageChest"} -- Updates bags values function BackpackLoot() for i,v in pairs(ItemTable) do if script.Parent.Parent.InteractGui.Adornee.Parent.Name ~= v then local DeadBackpack = script.Parent.Parent.InteractGui.Adornee.Parent.Name StorageItem.Wood.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Wood.Value StorageItem.Cloth.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Cloth.Value StorageItem.Stone.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Stone.Value StorageItem["Raw Metal"].Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack]["Raw Metal"].Value StorageItem.Metal.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Metal.Value StorageItem["Raw Sulfur"].Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack]["Raw Sulfur"].Value StorageItem.Sulfur.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Sulfur.Value StorageItem.Charcoal.Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack].Charcoal.Value StorageItem["Raw Meat"].Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack]["Raw Meat"].Value StorageItem["Cooked Meat"].Amount.Text = ReplicatedStorage.PlayerStats[DeadBackpack]["Cooked Meat"].Value elseif script.Parent.Parent.InteractGui.Adornee.Parent.Name == v then -- Do nothing end end end -- Fires the backpack event function AdorneeChanged() for j,m in pairs(ItemTable) do if script.Parent.Parent.InteractGui.Adornee.Parent.Name ~= m then for i,v in pairs(ReplicatedStorage.PlayerStats[script.Parent.Parent.InteractGui.Adornee.Parent.Name]:GetChildren()) do v.Changed:Connect(BackpackLoot) end elseif script.Parent.Parent.InteractGui.Adornee.Parent.Name == m then -- Do nothing end end end -- Fires to update bags values for i,v in pairs(ReplicatedStorage.PlayerStats[Player.Name]:GetDescendants()) do v.Changed:Connect(AdorneeChanged) end
So the problem is the "Fires the backpack even" shouldnt fire if the adornee.Parent.Name is equal to a string in the table, but it still does. Thats the problem, its like its ignoring the table completely. I tell it if the adornee.Parent.Name is equals to the table to do nothing but its still firing the function when its not supposed to do anything if the name equals a value in the table.
So any ideas?
UPDATE
I have been testing it and when you add any more than 1 variable to the table it breaks it, if there is only 1 variable in the table then it works fine but anymore than that and it breaks? Any ideas?