Attempt to concatenate nil with string

Hey guys! I hope y’all doing very very well! Being direct, I’m using Region3 to make a PlayerCount, and I want to show in a Gui that PlayerCount, the problem is that when I’m trying to pass the PlayerCount to the TextLabel, it gives me that error that you can see in the title:

image

Here’s the Region3 script (ServerScript):

local debounce = false
local playerfound = false

function CreateRegion3FromPart(Part)
	return Region3.new(Part.Position-(Part.Size/2), Part.Position+(Part.Size/2))
end

function GetPlayersInPart(part)
	local region = CreateRegion3FromPart(part)
	local partsInRegion = workspace:FindPartsInRegion3(region,nil,math.huge)
	local Players = {}
	local PlayerCount = 0
	
	for i, Part in pairs(partsInRegion) do
		local player = game.Players:GetPlayerFromCharacter(Part.Parent)
		if player then
			
			for i, v in pairs(Players) do
				if Players[i].Name == player.Name then
					playerfound = false
				end
			end
			
			if playerfound == false then
				table.insert(Players,player)
				PlayerCount = PlayerCount + 1
			end
			playerfound = false
			
		end
	end
	
	for i, v in pairs(Players) do
		
		game.ReplicatedStorage.RemoteEvents.ChangeCMPlayerCount:FireClient(Players[i], PlayerCount)
		
	end
	return Players
	
end

while wait(1) do
	GetPlayersInPart(game.Workspace.TeleportPlace.CompleteFullMatches.CMRegion)
end

Here’s the Client Event script (LocalScript):

game.ReplicatedStorage:WaitForChild('RemoteEvents').ChangeCMPlayerCount.OnClientEvent:Connect(function(player, PlayerNames, PlayerCount)
	
	local player = game.Players.LocalPlayer
	local playersInRegion = PlayerCount
	
	player:WaitForChild('PlayerGui').HowManyPlayersIn.PlayerCount.TextLabel.Text = "Players: "..playersInRegion.."/12"
	
end)


I don’t know really what can be messing the script in here, so if you can give me a hand with this, even if it’s the smallest one, I’ll appreciate it a lot! Thank you for everything and have a nice day! bye! :wave: :smiley:

Hello!

On the .OnClientEvent you do not need the player argument because it does not get sent by the server, and its not really needed because you can have a variable to the LocalPlayer :slight_smile:

Try removing the “player” argument here and test it out

But so how can I get the number of players that are in the Region3?

game.ReplicatedStorage:WaitForChild('RemoteEvents').ChangeCMPlayerCount.OnClientEvent:Connect(function(PlayerCount)
	

Just realised you’re not sending the playernames either only player count, you just need to do it like the code above, also to tell all the players you can do :FireAllClients() instead of looping through them

1 Like

Thank you so much! I appreaciate everything! Have a nice day and a nice life :wave: :smiley:

1 Like