I need help with If Statements and the For Loop

I don’t know if I can make it very clear because it’s something a bit complex for me, but what I wanted to do is when the player entered the game he would receive a clan and then I created an if statement in case the player got a certain clan, adding attributes to the player

Okay, to select
the player’s clan I made a function where it would select a clan for the player
using the For Loop:


local clansChance= {

			zoldyck = 10000,

			kurta = 0.1,

			freecs = 1,

			netero = 1,

			kreuger = 5,

			portor = 60,

			tsezguerra = 60,

			bordeau = 60,

			hatake = 60,

			magcub = 60,

			takano = 60,

			hazama = 60,

			todoroki = 60,

			}

local sum = 0
		
		for _,clans in pairs(clansChance) do
			
			sum = sum + clans
		end
		
		local function SetPlayerClan()

			local clanValue = Random.new():NextNumber(0,sum)

  
			for item,value in pairs(clansChance) do


			
				clanValue = clanValue - value

				if clanValue < 0 then
					
					print(item)
					return item
				end
			end
		end

		plrData.Clan = SetPlayerClan()
		print("Your Clan is".. plrData.Clan.."!")

Here are the if statements for each clan:

if plrData.Clan == clans.freecs  then


			plrData.Potential = plrData.Potential + clans.freecs.potential
			print(plrData.Potential)
			print(plrData.Clan)
			plrData.Speed = plrData.Speed + clans.freecs.speed
			plrData.Strenght = plrData.Strenght + clans.freecs.strenght
			plrData.Defense = plrData.Defense + clans.freecs.defense

		elseif plrData.Clan == clans.kreuger  then

			plrData.Potential = plrData.Potential + clans.kreuger.potential
			print(plrData.Clan)
			plrData.Speed = plrData.Speed + clans.kreuger.speed
			plrData.Strenght = plrData.Strenght + clans.kreuger.strenght
			plrData.Defense = plrData.Defense + clans.kreuger.defense

		elseif plrData.Clan == clans.netero  then

			plrData.Potential = plrData.Potential + clans.kreuger.potential
			print(plrData.Clan)
			plrData.Speed = plrData.Speed + clans.netero.speed
			plrData.Strenght = plrData.Strenght + clans.netero.strenght
			plrData.Defense = plrData.Defense + clans.netero.defense

		elseif plrData.Clan == clansChance.kurta then

			plrData.Potential = plrData.Potential + clans.kurta.potential
			print(plrData.Potential)
			print(plrData.Clan)
			
			plrData.Speed = plrData.Speed + clans.kurta.speed
			plrData.Strenght = plrData.Strenght + clans.kurta.strenght
			plrData.Defense = plrData.Defense + clans.kurta.defense

		elseif plrData.Clan  == clansChance.zoldyck then

			plrData.Potential = plrData.Potential + clans.zoldyck.potential
		
			print(plrData.Potential)
			plrData.Speed = plrData.Speed + clans.zoldyck.speed
			plrData.Strenght = plrData.Strenght + clans.zoldyck.strenght
			plrData.Defense = plrData.Defense + clans.zoldyck.defense
		end

Now, the problem is that even if the player’s clan is the same as the clan that was selected, the if statement is not activated

I tried searching on the internet but I didn’t find a case similar to mine, and this is something new for me and complex too

Waiting for answers

1 Like

I don’t know what your clans table is, but I’m assuming it looks like this:

local clans = {
	freecs = 123
	-- ...rest of items
}

The issue may be plrData.Clan is the clan name, and clans.freecs is the value 123 and NOT the name “freecs”. So your if statement should be more like this:

if plrData.Clan == "freecs" then
3 Likes

Oh my God, I didn’t think of that, thank you so much

2 Likes

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