Why does this work fine the first time?

I’m currently working on a party system and I’m trying to do the kicking part of it so the party leader can kick other players and this is what I have so far however for some reason it seems work just fine the first time but after this runs again it just doesn’t?

KickFromParty.OnServerEvent:Connect(function(Player,PlayerToKick)
	
	local Party = PlayerManager:GetData(Player,"Party")

	for i,Plr in pairs(Party["InParty"]) do
		
		if Plr.Name == PlayerToKick then
			
			table.remove(Party["InParty"],i)		
			
			PlayerManager:ChangeStat(Plr,"Party",{Host = "",InParty = {}})
			
			DisbandParty:FireClient(Plr) 
			
		end
		
	end
	
	if #Party["InParty"] <= 1 then
		
		print("Disband")
		
		PlayerManager:ChangeStat(Party["InParty"][1],"Party",{Host = "",InParty = {}})
		
		DisbandParty:FireClient(Party["InParty"][1])
		
	else
		
		print("Update Party")
		
		for _,Plr in pairs(Party["InParty"]) do

			PlayerManager:ChangeStat(Plr,"Party",Party)

			KickedFromParty:FireClient(Plr,PlayerToKick)

		end		
		
	end
	
end)

Output the first time you kick a player
Server - Roblox Studio 1_30_2021 10_50_39 PM (2)

Output the second attempt as you can see it doesn’t actually remove the player as it still ends up printing 2.
Server - Roblox Studio 1_30_2021 10_50_34 PM (2)

EDIT: I updated the script, but it still only works the first time :confused:
EDIT 2: Ok so turns out the issue wasn’t even because of this it was because of another function that added the player twice L.

1 Like

I am trying to help but am not able to see the lines of code that print 1 or 2.

Oh it’s this line near the bottom.

warn(#NewParty["InParty"])

Edit: Also I realized that the way I did this was stupid I don’t think it’s necessary to do the newparty thing I did

1 Like