How Do I Make It Show Player Count On a ui?

Hello there,

I am trying make these script show a player count On a gui and It’s not showing a list of players. If someone could help my issue that would be great!

GUIHandler

local function updateGui()
	
	
	local serverFrames = {}
	
	
	for i, serverValue in pairs(game:GetService("ReplicatedStorage").Servers:GetChildren()) do
		
		local name = serverValue.Name
		
		local serverStats = string.split(serverValue.Value, " ")
		
		local id = serverStats[1]
		local plrs = serverStats[2]
		
		
		local serverFrame = script.ServerTemplate:Clone()
		
		serverFrame:WaitForChild("ServerName").Text = name .. "\n ID: " .. id
		serverFrame:WaitForChild("Players").Text = plrs .. "/" .. game:GetService("Players").MaxPlayers
		
		
		table.insert(serverFrames, serverFrame)
		

		serverFrame.JoinButton.MouseButton1Click:Connect(function()
				
game:GetService("TeleportService"):TeleportToPlaceInstance(game.GameId, id)
		end)

		
		script.Parent.List:ClearAllChildren()

		script.UIListLayout:Clone().Parent = script.Parent.List
		
		
		for i, serverFrame in pairs(serverFrames) do
			
			serverFrame.Parent = script.Parent.List
		end
	end
end


updateGui()

game:GetService("ReplicatedStorage").Servers.ChildAdded:Connect(updateGui)
game:GetService("ReplicatedStorage").Servers.ChildRemoved:Connect(updateGui)

ServerHandlers

local serversFolder = game.ReplicatedStorage:WaitForChild("Servers")

local ms = game:GetService("MessagingService")

ms:su("ServerList", function(data)

	
	data = data.Data
	
	
	if data.serverId ~= game.JobId then
		
		
		local ServerValue = script.ServerName:Clone()


		ServerValue.Name = "Server" .. #serversFolder:GetChildren() + 1

		
		ServerValue.Value = data.serverId .. " " .. data.players

		ServerValue.Parent = serversFolder
		
		wait(5)
ServerValue:Destroy()
	end
end)


while game.VIPServerId == "" do
		
	
	local data = {
		serverId = game.JobId,
		players = #game:GetService("Players"):GetPlayers()
	}
	
	ms:PublishAsync("ServerList", data)
	
	
	wait(5)
end
  • Official_SimuIation
ms:su("ServerList", function(data)

	
	data = data.Data
	

dont do data.Data you have the dictionary it doesnt save the variable name
just remove that and that solves the problem I could see

1 Like

It Still Doesn’t Show Anything. Is There a Problem With Place id?

If I got it right and you meant a player count, you could add a ChildAdded and Removed event to Players in a LocalScript and set the Text inside the UI to show the number of players.

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local PlayerUI = PlayerGui:WaitForChild("PlayerUI")

local PlayerCount = PlayerUI.PlayerCount
PlayerCount.Text = #Players:GetPlayers()

local function ChildTracker(child)
	local PlayerAmount = #Players:GetPlayers()
	
	if child:IsA("Player") and child.Parent == Players then
		PlayerCount.Text = PlayerAmount
	else
		PlayerCount.Text = PlayerAmount
	end
end

Players.ChildAdded:Connect(ChildTracker)
Players.ChildRemoved:Connect(ChildTracker)

So I Add that in the Text? or some where else

I couldn’t understand some of your scripts very well, that is just an example, but if you’d like, you could make it as a side script.

1 Like

local Players = game:GetService(“Players”)
local playerCount = Players.NumPlayers

local ScreenGui = Instance.new(“ScreenGui”)
local TextLabel = Instance.new(“TextLabel”)

TextLabel.Text = "Player Count: " … playerCount
TextLabel.Parent = ScreenGui

(Lemme know if this works i cant test this rn and in fairly new at scripting)

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