Problem with tables. No output

I’m working on a build system and only know how to use tables very basically.

When you click the faction change button in the gui menu it changes your faction value which triggers a function that changes all of the values inside of a folder in the gui [according to faction stats]. Those values are what i’m going to use to determine what size an image label needs to be. My problem is the script runs fine without throwing an error but does not do what it needs to do. It changes the faction value and triggers the function but the problem lies within that function it’s most likely a table problem but i’m not sure where. any help would be appreciated thanks in advance.


--Faction types
local Sorcerer = {Speed = 1 , Health = -25 , Defense = -5, Attack = 25,Stamina = 25, Endurence = 0}
	local Orc = {Speed = 1.25, Health = 0, Defense =15, Attack = -10, Stamina = 50, Endurence = -10}
		local Titan = {Speed = -1.25, Health = 75, Defense = 25, Attack = 10, Stamina = -15, Endurence = 0}
			local Factions = {Sorcerer, Orc, Titan}




-- choose your faction [THIS IS SUPPOSED TO TRIGGER BELOW WHEN IT CHANGED THE FACTION VALUE]
FactionChooser:FindFirstChild("Faction").MouseButton1Click:Connect(function()
	if FactionChooser:FindFirstChild("Faction").Text == ("Sorcerer") then
		FactionChooser:FindFirstChild("Faction").Text = ("Orc")
		config:FindFirstChild("Faction").Value = ("Orc")
	elseif FactionChooser:FindFirstChild("Faction").Text == ("Orc") then
		FactionChooser:FindFirstChild("Faction").Text = ("Titan")
		config:FindFirstChild("Faction").Value = ("Titan")
	elseif FactionChooser:FindFirstChild("Faction").Text == ("Titan") then
		FactionChooser:FindFirstChild("Faction").Text = ("Sorcerer")	
		config:FindFirstChild("Faction").Value = ("Sorcerer")
	end
end)

-- config faction type changed remove prev faction stats from stat folder and add new ones up 
config.Faction.Changed:Connect(function()
	print("att changed")
	for a, b in ipairs(Factions) do
		if config.Faction.Value == b then
			--local CurrentFaction = table.find(b)
			local PrevFaction

			if a == 1 then PrevFaction = table.find(Titan)
			else PrevFaction =  table.find(Factions[a - 1])
			end

			for c, d in ipairs(StatTracker:GetChildren()) do
				-- gets all stats in stattracker and changes val
				local TempNewStat = table.find(b,d.Name)
				local TempOldStat = table.find(PrevFaction, d.Name)

				d.Value = (d.Value - TempOldStat + TempNewStat)

			end


		end
	end
end)










1 Like

table.find needs 2 arguments. the first being the table, and the second being the content you are looking for. you only specify the first argument in your PrevFaction variable.

You can store FactionChooser:FindFirstChild(“Faction”) in a variable instead of FindFirstChild constantly which could error if it doesnt exist. Always check if things exist before attempting to use them.

1 Like