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
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)
3 Likes

As first you doesn’t get the local player

Make sure the local script is accessible for the player

Then in the server use fireallclients to fire the remote to all clients

2 Likes

For your third line.

It fires PLRNames to all clients and in my local script it calls that remote

ServerScript

ReplicatedStorage.JoinServers.JoinServerServer.OnServerEvent:Connect(function(player)
	ReplicatedStorage.PLRNames:FireAllClients(player.Name)
	local MaxPlayerValue = MaxPlayersFolder:FindFirstChild(player.Name .. " 's Server")
	if MaxPlayerValue then
		MaxPlayerValue.Value = MaxPlayerValue.Value + 1
		
		if MaxPlayerValue.Value >5 then
			print("more than five players")
		end
	end
end)

Also, what do you mean, make the local script accessible for the player?

2 Likes

Idk sometimes when I put a script in ReplicatedStorage it doesn’t work but when in starter player it does

Also you can use game.players.playeradded in the server script when a player joins

2 Likes

Its not joining the game its joining a sever. It’s a ui server thing I am wanting to make.

1 Like

Then where are the remote events fired to the client

1 Like

Also If you would like to see the two server scripts, here they are:

MaxPlayers:

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

local MaxPlayersFolder = ServerScriptService.MaxPlayers.MaxPlayersFolder

ReplicatedStorage.MaxPlayers.OnServerInvoke = function(player)
	
	local MaxPlayersValue = Instance.new("NumberValue")
	MaxPlayersValue.Parent = MaxPlayersFolder
	MaxPlayersValue.Value = 1
	MaxPlayersValue.Name = player.Name .. " 's Server"
	
	print(player)


	
	if MaxPlayersValue then
		return true
	else
		return false
	end


end 

ReplicatedStorage.JoinServers.JoinServerServer.OnServerEvent:Connect(function(player)
	ReplicatedStorage.PLRNames:FireAllClients(player.Name)
	local MaxPlayerValue = MaxPlayersFolder:FindFirstChild(player.Name .. " 's Server")
	if MaxPlayerValue then
		MaxPlayerValue.Value = MaxPlayerValue.Value + 1
		
		if MaxPlayerValue.Value >5 then
			print("more than five players")
		end
	end
end)

ReplicatedStorage.CloseFunction.CloseServerUI.OnServerEvent:Connect(function(player)
	local MaxPlayerValue = MaxPlayersFolder:FindFirstChild(player.Name .. " 's Server")
	if MaxPlayerValue then
		MaxPlayerValue.Value = MaxPlayerValue.Value - 1
	end
end)local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local MaxPlayersFolder = ServerScriptService.MaxPlayers.MaxPlayersFolder

ServerIDHandler:

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"

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 = ServerScriptService.ServerIDHandler.ServerNames
	-- set the parent as the last property because it's more optimized

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


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

	return ServerID
end

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



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)
1 Like

Join = It fires when a player enters the right ServerID ( a randomised 5 number code)
Creating Server = Remote event (in the local script it is called CreateServerPlayer) fires when a player creates the server

1 Like

I think maybe the other player have only one name cuz the other name is fired when other player didn’t joined yet

1 Like

You could clone the UI with the names when a new player joins and also update that

1 Like

I have no idea. If it makes it easier can you come into my game? It will simplify things a lot easier since you have access to all of the scripts.

1 Like

Just in the server script fire it name to all clients and also update the a frame in startergui to where the players show up then if an new player joins they get the frame from startergui

Also I don’t recommend to add random people to your game as they can do things to your game or steal your stuff I once worked with a team then somoane of that team removed my stuff

2 Likes

What remote event do I fire?

How would I update the text label?

Also are you thinking of a game server?
Here is a video of what there is:

Idk why but it cut out the beggining of the clip
The begining was creating the Server.

1 Like

Make sure to update what you do on the clients also in starter Gui if it’s isn’t updating there new joined players won’t see it they get what’s in startergui on join not what other clients have

1 Like

Im sorry, but I am having a hard time trying to understand what you are saying.

1 Like

So let’s we say we have some containers

Startergui,
StarterCharacterScripts,
Starter player scripts,

When a player joins this containers being cloned to

Player Gui,
Character,
player scripts,

So you change some things to the clients player Gui uis now

On the server also make this changes to the startergui

So basicly what you are saying is that you clone the containers to each Player GUI, character and player scripts. Or am i completely wrong.

1 Like

Yes that happens automatically when a player joins

How would I save the data (the text labels and the text) to the server which then it can fire a remote event to the clients in the ui server? (lets call it ui server instead of server to not get confused)

Just also on the server use the ui in startergui to do the same as you do with the fireallclients after rrcijved on the client