The “PlayerName” is the text label that shows the names of players:
I will call “PlayerName” text label.
Here is what is supposed to happen:
A player creates a server
The text label changes its text to the server creator’s username
A player joins with the correct ServerID
The text label clones and changes its text to the player’s username
Here is what actually happens:
A player creates a server
the text label changes its text to the server creator’s username
A player joins with the correct ServerID
The text label does NOT clone, therefore not changing the text label’s text to the player’s username
Now I think the problem is with the boolean variable, “InServer” though I am not quite sure.
In the first remote, (where “InServer” is located) I added a print statement which prints the state of “InServer” and it does print true (which is good!) but it prints after the player has joined therefore, “InServer” is false and does not clone the text label. I am not 100% sure that is the reason, but it is worth a try.
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)
It seems like the issue might be related to how the InServer flag is being used and when it’s checked. One possibility is that when a player joins the server, the script sets InServer to true, but the cloning of the text label happens before this change is fully processed. This could lead to the InServer flag being in the wrong state when the label is supposed to be cloned, which might be why the player’s name doesn’t show up as expected. Another way could be that the InServer flag is being reset too soon, which might prevent the label from cloning properly. To fix this, maybe it would help to make sure that InServer is set to true only after the player has fully joined, and not reset it until the cloning is complete. Adding a small delay before checking if the player is in the server could also give the script enough time to handle everything properly. If this is the case, adjusting the timing or flow could ensure that the text label is cloned correctly and shows the player’s name.
When I delay this part of the script longer, it then has time to make InServer true, which then clones the textlabel!
game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname)
task.wait(10)
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)
It is a pyscological horror game about manequins that chase you. If you look at them they stand still and if you don’t look at them, the manequins will follow you.
And thanks the ui design didn’t take too long to make since I used a website call Figma, but it did look better on the website.
Well the delay does not need to be there, I just added it to be sure. Also I have made a post on another issue that I stated on the reply that your reacted to. I would like for you to check it out!