TextLabel.Text doesn't appear for different players

Hello!

I have made two scripts, a local and server script.

In the server script, it makes a string value in ServerScriptService.ServerIDHandler(the server script).ServerNames.
The string value.value is the names of the server’s e.g (planeboy2021’s SERVER)

Then it invokes a remote function to the local script with the parameters, player, ServerName.

    local ServerName = Instance.new("StringValue")
	ServerName.Name = player.Name.. "'s SERVER"
	ServerName.Value = player.Name.. "'s SERVER"
	ServerName.Parent = ServerScriptService.ServerIDHandler.ServerNames
	-- set the parent as the last property because it's more optimized

	game:GetService("ReplicatedStorage").ServerNames:InvokeClient(player, ServerName.Value)

This works fine.

In the local script, it takes that information and changes the serverName.text to the ServerName.value

local player = game:GetService("Players")

local ServerGui = script.Parent
local ServerName = ServerGui.Server.ServerName

game:GetService("ReplicatedStorage").ServerNames.OnClientInvoke = function(PlayerServerName)
	print(PlayerServerName)
	
	ServerName.Text = PlayerServerName
end

However, when I played with two clients, for player 1 which created the server worked fine, but for player two which joined the server, the ServerName still said “SERVER NAME”

Any solutions?

Try using RemoteEvents, rather than RemoteFunctions

Not 100% sure if that is part of the issue, but is still a change that you should be making.

edit: Yeah, I don’t think it is related but I’ll keep looking.

Just to clarify:

Are all players meant to see the same text in the textlabel, at all times? Or will it be possible for players to view different text than what another player is seeing

its the servercreator’s name e.g (planeboy2021’s SERVER) I want it to display the creator name on the text label.

Also the remote events did not work. :frowning:

So will players be able to change to another player’s server, without leaving the game?

I am confused by what you said, can you explain what you are meaning?

Will the text ever need to change after it has been set to, for example, “planeboy2021’s server”

Yes the text will be changed if a player has joined a different server.
@SeargentAUS

In the server script, you only invoke the player who owns the server. Loop through all players in the server and invoke each of them.

Also, instead of using RemoteFunctions for Server to Client communication, you should use RemoteEvents (like @SeargentAUS suggested).

1 Like

I think it is problem with

game:GetService("ReplicatedStorage").ServerNames:InvokeClient(player, ServerName.Value)

You need to send the player receiving the Invoke signal as an argument, but since only the server owner player is sent, the signal only goes to that player.

So, use for loop to give both two players a signal.

2 Likes

How would I use a for loop? And what do you mean by signal?

How would I invoke all the players with a loop? can you provide an example please!

Just use this code instead.

for _, ReceivePlayer in ipairs(game.Players:GetPlayers()) do
    game:GetService("ReplicatedStorage").ServerNames:InvokeClient(ReceivePlayer, player, ServerName.Value)
end
1 Like

I got this error

21:49:21.126 Unable to assign property Text. string expected, got Instance - Client - ServerJoinCreateScript:12

Script: local

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

local CreateBTN = ScreenGUI.ServerSelect.CreateServer
local ServerIDNum = ScreenGUI.Server.CreaterPanel["Server ID"].SERVERIDNumber
local ServerName = ScreenGUI.Server.ServerName

ScreenGUI.Server.CreaterPanel.Visible = false

CreateBTN.MouseButton1Click:Connect(function()

	local ServerID = game.ReplicatedStorage.CreateServer:InvokeServer() -- This line
	if ServerID then
		print("Created server with ID:", ServerID)

		ScreenGUI.Server.Position = UDim2.new(0.5, 0,0.365, 0)
		ScreenGUI.ServerSelect.Visible = false
		ScreenGUI.Server.CreaterPanel.Visible = true
		ScreenGUI.Server.Visible = true
		ServerIDNum.Text = ServerID
		ServerName.Text = Players.LocalPlayer.Name .. " 's SERVER"
		
		
	else
		warn("Failed to create server")
	end
end)

This local script detects if a player has clicked on the create button. And sends a remotefunction

Could you send Server Script, too?

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.CreateServer.OnServerInvoke = function(player)
	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.. "'s SERVER"
	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:InvokeClient(ReceivePlayer, player, 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
		end
	end)

	return ServerID
end

ReplicatedStorage.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)
			
			
			
			return true
		end
	end
	warn(player.Name .. " failed to join server with ID:", ServerID)
	return false
end
1 Like

Could you change player to player.Name? I think it causes an error because you send Instance argument instead of string.

What line and script is that one? Can you block quote the line please!

This line. (I typed it because of least characters limit.)

1 Like

That fixed the Error and now I can see the server Creators Name thanks!