For i, v in pairs() only works for one player

This only works for one person, please help.

Script:

game.ReplicatedStorage.deleteGang.OnServerEvent:Connect(function(plr, gangName)
	for i, v in pairs(game.Players:GetChildren()) do
		if v.gangSystem.gangName.Value == plr.gangSystem.gangName.Value then
			v.gangSystem.gangName.Value = ""
			v.gangSystem.isOwner.Value = false
			v.gangSystem.gangColour.Value = Color3.new()
			v.gangSystem.isInGang.Value = false
			game.Workspace:FindFirstChild(v.Name).Head.gangGUI:Destroy()
			game.Workspace:FindFirstChild(v.Name).Head.usernameGUI.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		end
	end
end)

What exactly is the gangSystem object that you are getting from the player? Could you provide more info please?

That’s just the folder it’s in.

I had the same issue for i,v in pairs() works for one player only if you are using onserverevent just make onclientevent or so

I prefer to leave it as onserverevent.

does any type of error appear?
if it does what does it say?
also i suggest where you use
in pairs(game.Players:GetChildren())
to make it into
in pairs(game.Players:GetPlayers())
because it could get non player instances but thats up to you

Any errors? This code is definitely running when there are more than one player in the game? It looks totally fine otherwise.

It doesn’t have any errors, and GetPlayers() has the same result.

Yes, I tested it with 2 players.

perhaps if there are no errors and there is the same output with GetPlayers() then
the place where you check “if then” skips the part of some people
have you checked that the result of “true” is on the “if then” for each player?

I have figured out the issue, it was due to the player’s message being incorrect. Thanks for the help anyway.

No problem i knew it was either the value being given or the if , then .
I’m glad to find out you sorted it out.

2 Likes