Script reads both If and elseif’s contents

Hello, so I’ve ran into a problem in my script while doing final bug fixes
Here is the script:

for i,v in ipairs(game.Teams:GetChildren()) do
	if v.TeamColor ~= gang.TeamColor then
		plr.Team = game.Teams:WaitForChild(gang.Name)	
	elseif v.TeamColor == gang.TeamColor then
		game.ReplicatedStorage.GangSystem.ClientFire:FireClient(plr)
	end	
end	

Basically what it does is it both fires the client and teams the player, I really don’t know where’s the problem.
Thank you for your time

Yeah, you’re using a loop so it goes through all the teams and if one of them has TeamColor equal to gang’s TeamColor then it fires. Assuming that gang is a team, the content in the elseif will be ran once and the elseif will be ran for every other team.

1 Like

Yeah but it also runs when it’s not equal to the teamcolor for some reason.
(the elseif)

[spoiler]Did i understand well?[/spoiler]

Also, i honestly think you can use else instead of elseif.

1 Like

I tried to use else but I changed it because of the same error.
(also what do you mean “Did I understand well?”
ok, might’ve understood what you meant.
It’s because the gang itself is a member of teams…

Also, did you try/could you try putting print statements?

1 Like

Yeah, but don’t worry, I fixed it, the problem was that the gang itself was a child of teams.
Thank you for your time.

1 Like

Yes, I’ve also been experiencing problems with my code where the if and elseif statements are being read in one go
I have a loop with 2.5s wait, and I want to iterate a value 3 times
while wait(2.5) do
if Value == 1 then
– do first code
elseif Value == 2 then
– do second code
elseif Value == 3 then
– do third code
end
Value = Value + 1
if Value > 3 then
Value = 1
end
end

For some reason it doesn’t have a frequency of 7.5 seconds but instead has this pattern:
1 wait skip 2 go3
3 wait skip 1 go2
2 wait skip 3 go1

and repeats