How to make Textlabel.Text show player.Name

Hello!!!:grin:

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

I want to make so when the local script receives a remote function, it changes the ServerName (textlabel) to player.Name:

What it looks like right now:
Screenshot 2024-12-31 100433

What its supposed to look like:
image_2024-12-31_100539509
Dont mind about the blue outline

In the serverscript, I donā€™t know where to put the

RemoteFunction:InvokeClient.

without disrupting the script.

I want it to be when the player creates the server it, the sends the remote function to the client. (Remote function for player creating server[ is called CreateServer) (Remote function for sending it to the client is called CreateServerPlayer)

Now when the player joins the server, it recieves a remote function, then I want it to send a remote function to the client, where it then clones the textlabel(PlayerName) and change the text to the player.Name who joined the server. (Remote function for player joining server is called JoinServer) (Remote function for sending it to the client is called JoinServerPlayer)

Here are the full scripts: (add to serverscript so it sends both remote functions to the client)

serverscript:

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.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
		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

Local script

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

game.ReplicatedStorage.CreateServer.OnClientInvoke = function(player)
	print("recieved")
	PlayerNameText.Text = player.Name
end
	
	
game.ReplicatedStorage.JoinServerPlayer.OnClientInvoke = function(player)
		
	PlayerNameText:Clone()
	PlayerNameText.Text = player.Name
		
end	
1 Like

I may be missing something here but when you do

`PlayerNameText:Clone()`

you need to parent that clone to your UI

so you can do

local playerTextClone = PlayerNameText:Clone()
playerTextClone.Parent = [where you want it to be located]

you would not be here without one of your parents, so thatā€™s why you must give the newborn object (your cloned textlable) a parent. BOOM (we bring the BOOM) and that should work :+1:

2 Likes

Ok great! now where do i put the CreateServerPlayer and JoinServerPlayer invokeclient() in the serverscript?

Because in my local script it calls those remote functions to work.

1 Like

sorry i must of missed that part

I never used ā€œinvokeā€™sā€ before, so like i have no idea what it is so sorry if i mess something up

but cant you just place it under these lines?

ReplicatedStorage.CreateServer.OnServerInvoke = function(player)
ReplicatedStorage.JoinServer.OnServerInvoke = function(player, ServerID)

Iā€™m not to sure what you mean

Nope unfortunatly when I did that, it messed up the ui.
What it looks like now.
Screenshot 2024-12-31 120158

What its supposed to look like:

Iā€™m guessing its cause of the ā€œInvokeā€ function thingy

it seems to be yielding the server causing all the other code to not run

is there any way you could switch ā€œinvokeā€ with ā€œFireClientā€ or ā€œFireAllClientsā€ Iā€™m not to sure if there is a better way

I seen this video https://www.youtube.com/watch?v=0H_xcA-0LDE&ab_channel=sleitnick

Title: " RemoteFunctions: Donā€™t use InvokeClient"
I dont know if this is to related to you it could have a whole diffierent case. But may as well give it a watch

I got this error when switching to remote events on local script

12:16:30.814 Players.planeboy2021.PlayerGui.ServerGUI.Server.Players.PlayersScript:12: attempt to index string with ā€˜Parentā€™ - Client - PlayersScript:12

script

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

if game.ReplicatedStorage.CreateServerPlayer.OnClientEvent then
	print("recieved")
	PlayerNameText.Text = Players.LocalPlayer.Name
end

if game.ReplicatedStorage.JoinServerPlayer.OnClientEvent then
	local playerTextClone = PlayerNameText:Clone()
	playerTextClone = Players.LocalPlayer.Name
	playerTextClone.Parent = script.Parent -- this line
end

on the OnClientEvents you have to put OnClientEvent:Connect(Function()

When i did that it messed up the ui.

What it looks like now.
Screenshot 2024-12-31 120158

What its supposed to look like:

Script:

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

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

	print("recieved")
	PlayerNameText.Text = Players.LocalPlayer.Name
end)

game.ReplicatedStorage.JoinServerPlayer.OnClientEvent:Connect(function()
	local playerTextClone = PlayerNameText:Clone()
	playerTextClone = Players.LocalPlayer.Name
	playerTextClone.Parent = script.Parent
end)

Try to remove the new lines of code and see if the UI still stays the same

also add some print statements that could help tell you where the error starts

I added a print statement, and it didnā€™t print out.

ReplicatedStorage.CreateServer.OnServerInvoke = function(player)
	 
	print("CreateServer") -- the print statement
	
	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.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
		end
	end)

	return ServerID
end

I think it is because of this, but iā€™m not quite sure

ReplicatedStorage.CreateServer.OnServerInvoke = function(player)
	ReplicatedStorage.CreateServerPlayer:FireAllClients(player)
end

ReplicatedStorage.JoinServer.OnServerInvoke = function(player)
	ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end

yeah honestly i donā€™t know bro

sorry!

1 Like

That is alright I will ask someone new.

1 Like