Text label clone doesn't appear for other players

Hello!

I’ve got an issue in my game where when a text label gets clones it only appears for the player it cloned on and not any others.

Player 2’s screen

Screenshot 2025-01-05 104559
Player 1’s screen

As you can see on Player 2’s screen it only shows the text label with their username on it

While on Player 1’s screen it shows both text labels.

local script:

local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText

local myServerName
local InServer = false

game:GetService("ReplicatedStorage").JoinServers.JoinServerPlayer.OnClientEvent:Connect(function()
	
	InServer = true
	print(InServer)
end)

game:GetService("ReplicatedStorage").ServerNames.OnClientEvent:Connect(function(player, ServerName)
	-- Invokes in ServerIDHandler
	print(ServerName .. "PLAYERS SCRIPT")
	
	myServerName = ServerName
	
end)

game.ReplicatedStorage.CreateServers.CreateServerPlayer.OnClientEvent:Connect(function(plr)

	local label = PlayerNameText
	label.Text = plr.Name
	label.Parent = script.Parent
	
end)

game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname) 
	task.wait(0.1)
	if InServer == true then
		print(tostring(plrname)) 
		local playerTextClone = PlayerNameText:Clone()
		playerTextClone.Text = tostring(plrname)
		playerTextClone.Parent = script.Parent
		playerTextClone.Name = plrname
		InServer = false
	else
		print("Player is not in server")
	end
	
	
end)
	
game.ReplicatedStorage.CloseFunction.LeaveServer.OnClientEvent:Connect(function(player)
	
	if Players.LocalPlayer.Name == myServerName then
		print("PlayerNameText is not getting destroyed because the player is the server creator")
	else
		local PlayerTextClone = script.Parent:FindFirstChild(Players.LocalPlayer.Name)

		PlayerTextClone:Destroy()
	end
	
	
end)
1 Like

It’s likely that you used :FireClient() in the serverscript on 1 player which means this only happens to 1 player. You should probably fire it to the second player’s client in the Serverscript.

I am not sure if this is what you mean. I have edited the script.

What’s new

  • Made a variable called “PlayerName” which is set to " "
  • When the player joins the server it sets “PlayerName” to the player’s username
  • When a server created it checks if “InServer” == true, if then it clones the text label and sets the text to “PlayerName”

But, on the server creator’s screen it still doesn’t show the text labels from the players who joined

Server Creators Screen:
Screenshot 2025-01-05 104559

Player who joined the server screen:

Local script:

local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText

local myServerName
local InServer = false
local PlayerName = ""

game:GetService("ReplicatedStorage").JoinServers.JoinServerPlayer.OnClientEvent:Connect(function()
	
	InServer = true
	print(InServer)
end)

game:GetService("ReplicatedStorage").ServerNames.OnClientEvent:Connect(function(player, ServerName)
	-- Invokes in ServerIDHandler
	print(ServerName .. "PLAYERS SCRIPT")
	
	myServerName = ServerName
	if InServer == true then
		local playerTextClone = PlayerNameText:Clone()
		playerTextClone.Text = PlayerName
		playerTextClone.Parent = script.Parent
		playerTextClone.Name = PlayerName
	end
end)

game.ReplicatedStorage.CreateServers.CreateServerPlayer.OnClientEvent:Connect(function(plr)

	local label = PlayerNameText
	label.Text = plr.Name
	label.Parent = script.Parent
	
end)

game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname) 
	task.wait(0.1)
	if InServer == true then
		print(tostring(plrname)) 
		local playerTextClone = PlayerNameText:Clone()
		playerTextClone.Text = tostring(plrname)
		playerTextClone.Parent = script.Parent
		playerTextClone.Name = plrname
		PlayerName = plrname
		InServer = false
	else
		print("Player is not in server")
	end
	
	
end)
	
game.ReplicatedStorage.CloseFunction.LeaveServer.OnClientEvent:Connect(function(player)
	
	if Players.LocalPlayer.Name == myServerName then
		print("PlayerNameText is not getting destroyed because the player is the server creator")
	else
		local PlayerTextClone = script.Parent:FindFirstChild(Players.LocalPlayer.Name)

		PlayerTextClone:Destroy()
	end
	
	
end)

You use a RemoteEvent, which means there has to be a Serverscript(A normal script, not a local script) that fires all of these remote events. In the server script, you should use :FireClient() to both the player who is joining the server and the player who created the server.

1 Like

Something like this?
@Controlguyman

   for _, ReceivePlayer in ipairs(game.Players:GetPlayers()) do
   	game:GetService("ReplicatedStorage").ServerNames:FireClient(ReceivePlayer, player.Name, ServerName.Name)
   	print("for loop")
   end

This is the same remote event from my reply above yours and fires when a player cerates a server.

For the players who join the server:
It is from the same script

ReplicatedStorage.JoinServers.JoinServer.OnServerInvoke = function(player, ServerID)
	
	for _, server in ipairs(ListofIds:GetChildren()) do
		if server.Value == ServerID then
			print(player.Name .. " successfully joined server with ID:", ServerID)
			
			ReplicatedStorage.JoinServers.JoinServerPlayer:FireClient(player)
			return true
		end
	end
	warn(player.Name .. " failed to join server with ID:", ServerID)
	return false
end

@Controlguyman
Can you reply to this comment if you are here?

what output do you get from the local script? it could be that InServer is false when ServerNames is fired due to remotes being fired in the wrong order

this also looks suspicious, did you mean to clone it instead

I have made a new post, it is an error I’ve got, can you please check that out!

In here have different code in my scripts.

I attempted to reinspect your code, but i found no issue so try this:

Client

local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText

local myServerName
local InServer = false --You should also perform checks on the Server if a player is in a server
local PlayerName = ""

game:GetService("ReplicatedStorage").JoinServers.JoinServerPlayer.OnClientEvent:Connect(function()
	
	InServer = true
	print(InServer)
end)

game:GetService("ReplicatedStorage").ServerNames.OnClientEvent:Connect(function(player, ServerName)
	-- Invokes in ServerIDHandler
	print(ServerName .. "PLAYERS SCRIPT")
	
	myServerName = ServerName
	if InServer == true then
		local playerTextClone = PlayerNameText:Clone()
		playerTextClone.Text = PlayerName
		playerTextClone.Parent = script.Parent
		playerTextClone.Name = PlayerName
	end
end)

game.ReplicatedStorage.CreateServers.CreateServerPlayer.OnClientEvent:Connect(function(plr)

	local label = PlayerNameText:Clone() -- Not sure if you intended to clone this, but i added a :Clone() function
	label.Text = plr.Name
	label.Parent = script.Parent
	
end)

game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname:string) 
	task.wait(0.1)
	if InServer == true then
		print(plrname)
		local playerTextClone = PlayerNameText:Clone()
		playerTextClone.Text = plrname
		playerTextClone.Parent = script.Parent
		playerTextClone.Name = plrname
		PlayerName = plrname
		InServer = false
	else
		print("Player is not in server")
	end
	
	
end)
	
game.ReplicatedStorage.CloseFunction.LeaveServer.OnClientEvent:Connect(function(player)
	
	if Players.LocalPlayer.Name == myServerName then
		print("PlayerNameText is not getting destroyed because the player is the server creator")
	else
		local PlayerTextClone = script.Parent:FindFirstChild(Players.LocalPlayer.Name)

		PlayerTextClone:Destroy()
	end
	
	
end)

Server

local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerIDHandler = ServerScriptService:FindFirstChild("ServerIDHandler") or Instance.new("Folder", ServerScriptService)
ServerIDHandler.Name = "ServerIDHandler"

local ListOfIds = ServerIDHandler:FindFirstChild("ListofIds") or Instance.new("Folder", ServerIDHandler)
ListOfIds.Name = "ListofIds"

local ServerNames = ServerIDHandler:FindFirstChild("ServerNames") or Instance.new("Folder", ServerIDHandler)
ServerNames.Name = "ServerNames"

ReplicatedStorage.CreateServers.CreateServer.OnServerInvoke = function(player)
	print("CreateServer")

	local ServerID = tostring(math.random(10000, 99999))
	local ServerEntry = Instance.new("StringValue")
	ServerEntry.Value = ServerID
	ServerEntry.Name = player.Name .. " 's Server"
	ServerEntry.Parent = ListOfIds

	local ServerName = Instance.new("StringValue")
	ServerName.Name = player.Name
	ServerName.Value = player.Name .. "'s SERVER" 
	ServerName.Parent = ServerNames

	for _, receivePlayer in ipairs(game.Players:GetPlayers()) do
		ReplicatedStorage.ServerNames:FireClient(receivePlayer, player.Name, ServerName.Value)
	end

	player.AncestryChanged:Connect(function()
		if not player.Parent then
			local playerServerID = ListOfIds:FindFirstChild(player.Name .. " 's Server")
			if playerServerID then
				playerServerID:Destroy()
			end

			local playerServerName = ServerNames:FindFirstChild(player.Name)
			if playerServerName then
				playerServerName:Destroy()
			end

			ReplicatedStorage.CloseFunction.LeaveServer:FireAllClients(player)
		end
	end)

	return ServerID
end

ReplicatedStorage.JoinServers.JoinServer.OnServerInvoke = function(player:player, ServerID:number?)
	for _, server in ipairs(ListOfIds:GetChildren()) do
		if server.Value == ServerID then
			print(player.Name .. " successfully joined server with ID:", ServerID)

			ReplicatedStorage.JoinServers.JoinServerPlayer:FireClient(player)

			ReplicatedStorage.PLRNames:FireAllClients(player.Name)

			return true
		end
	end
	warn(player.Name .. " failed to join server with ID:", ServerID)
	return false
end

ReplicatedStorage.CreateServers.CreateServerServer.OnServerEvent:Connect(function(player)
	ReplicatedStorage.CreateServers.CreateServerPlayer:FireAllClients(player)
end)

ReplicatedStorage.CloseFunction.CloseServerUI.OnServerEvent:Connect(function(player)
	ReplicatedStorage.CloseFunction.LeaveServer:FireAllClients(player)
end)

Nope that didn’t work. Instead it messed up the text labels like this:

Server creator:

Players who joined the server:
Screenshot 2025-01-07 134819