Variable Value gets mysteriously overwritten

The value for Superpower seems to mysteriously change during the loop

Output:
output

Script:

for player, combination in pairs(SideEffectandPowerCombinations) do
			print(combination)
			for i, list in ipairs(combination) do
				local Superpower
				local SideEffect
				
				if i == 1 then
					Superpower = list[2]
				else
					SideEffect = list[2]
				end
				
				local arguements = {Superpower, SideEffect}
				print(Superpower)
				CreateGui:FireAllClients(arguements)
			end
		end

I don’t see anything that would magically the value of Superpower, help will be appreciated :smiley:

You’re defining the superpower variable within the scope and as such it’s getting removed at the end of the loop and then redefined at the start, and since its starting value is nil that’s why the values changing.

1 Like

Do you happen to know a way I can go about fixing the script? Didn’t know variables get deleted at the end of a loop

You simply define the superpower variable outside of the loop.

1 Like