Player.Name prints out nil

Hello!

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

In my server script I made a stringvalue and set the value to player.name, then sent it as a remote event to the client

In my local script it recieves a remote function and makes a text label and sets the text as player.name. Then it recieves the remote event that was sent from the server script, and clones that text label and puts the text as player.name.
However, when retrieving the player.name data, it breaks and sends out nil.

ServerScript:

ReplicatedStorage.MaxPlayers.OnServerInvoke = function(player)
	
	local MaxPlayersValue = Instance.new("NumberValue")
	MaxPlayersValue.Parent = MaxPlayersFolder
	MaxPlayersValue.Value = 1
	MaxPlayersValue.Name = player.Name .. " 's Server"
	
	local PlrNames = Instance.new("StringValue")
	PlrNames.Parent = script.PlrNames
	PlrNames.Value = player.Name
	PlrNames.Name = player.Name
	
	ReplicatedStorage.JoinServers.JoinServerPlayer:FireAllClients(PlrNames)
	
	if MaxPlayersValue then
		return true
	else
		return false
	end


end

Local script:

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

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

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

game.ReplicatedStorage.JoinServers.JoinServerPlayer.OnClientEvent:Connect(function(plrname) 
	print(tostring(plrname)) 
	local playerTextClone = PlayerNameText:Clone()
	playerTextClone.Text = tostring(plrname)
	playerTextClone.Parent = script.Parent
end)
game.ReplicatedStorage.CloseFunction.LeaveServer.OnClientEvent:Connect(function(player)
	local PlayerTextClone = script.Parent:FindFirstChild(Players.LocalPlayer.Name)
	PlayerTextClone:Destroy()
end)

Where is your ServerScript located? Your issue is probably because the PlrNames StringValue isn’t replicated, so trying to send it over turns it into nil. You parented it to the script, but depending on the script’s location it’s not replicating.

image_2025-01-03_131042291

That would explain it. ServerScriptService isn’t visible to clients, so PlrNames doesn’t replicate and becomes nil when you try to send it over.

2 Likes

You’re not giving the StringValue enough time to replicate on top of that. I don’t see a need for StringValues anyways. Just send the player’s username directly

Nope, it will never replicate because it’s not in a container that can replicate. Please read this article on the documentation: Remote Events and Callbacks | Documentation - Roblox Creator Hub

So what would I need to do? (Character Limit)

I am extremely familiar with the Roblox engine. I know it will fail to replicate. What I am saying is that in the event it would, not enough time is given to allow the instance to replicate—this is a factor to consider in the coming solution

Again, I don’t see the need to use StringValues here, or at least the need to send the one you created. Simply send the player’s username

1 Like

So something like this?

	ReplicatedStorage.JoinServers.JoinServerPlayer:FireAllClients(player.Name)

Yes. Something exactly like that

1 Like

Nope it still is nil

1 Like

I do not see any issues with your code beyond this point. It would be easier to diagnose the issue live. Add me on Discord @ziffix

This is also wrong. When you send an instance over a remote, it will prioritize replication if it wasn’t already available on the client. It will not happen if the instance is inherently non-replicable, or if the instance is outside of the streaming radius.

Alr, I sent a friend request!!!

Workspace.StreamingEnabled is enabled by default, hence my concern

Guys stop the beefing, we have different opinons on topics, and someone’s topics may be more correct over anothers but we do not need to ramble over and over again. :cry:

Anyways fellas, the text label still says nil.

Any one know how to fix it?

I’m awaiting further communication in DMs

1 Like

The issue has been resolved. Problems included:

  1. Source of username propagation failure: override of OnServerInvoke callback later in the script

  2. Source of nil username: additional firing of JoinServerPlayer event with no arguments in separate script

1 Like