Hello!!
I have made a ui server system so people can join people’s servers, which will then send them to a game place. This is system is used heavily in many games!
The “PlayerName” text label is the text label I am talking about.
I will call “PlayerName” text label
Here is what’s supposed to happen:
- A player makes a server
- the text label.text changes to the player.name (Server creator’s username)
- A player joins and clones the text label and changes text label.text to the players name
- Everyone in the server can see all the text label including server creator and people who joined the server
Here is what actually happens:
- A player makes a server
- the text label.text changes to the player.name (Server creator’s username)
- A player joins the server, changes the text label.text to their username and DOESN’T clone the text label.
- The server creator’s text label.text is still their username
- Everyone in the server can only see one text label and the text is their user name.
Here is the local script where it happens, and if you want to see the scripts where the remote functions and events fires/invokes, you can ask me!
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()
print("recieved")
PlayerNameText.Text = Players.LocalPlayer.Name
end)
game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname)
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)
1 Like
Sorry for the bump up but I haven’t got a reply for nearly 30 minutes
1 Like
This would be helpful if possible.
2 Likes
If you want the scripts that was fired/invoked by remotes here they are:
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
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
- Line 21: 3rd Remote
CreateServers.CreateServerServer is when the player creates a server (please don’t change that bit since it works fine!)
ReplicatedStorage.CreateServers.CreateServerServer.OnServerEvent:Connect(function(player)
ReplicatedStorage.CreateServers.CreateServerPlayer:FireAllClients(player)
end)
Line 28: 4th remote:
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)
ReplicatedStorage.PLRNames:FireAllClients(player.Name)
if MaxPlayersValue then
return true
else
return false
end
end
ReplicatedStorage.JoinServers.JoinServerServer.OnServerEvent:Connect(function(player)
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)
Line 43: 5th and last remote:
ReplicatedStorage.CloseFunction.CloseServerUI.OnServerEvent:Connect(function(player)
ReplicatedStorage.CloseFunction.LeaveServer:FireAllClients(player)
end)
The CloseFunction.CloseServerUI is when the player clicks the close button (top right “X” button)
2 Likes
You never added code logic to create the new textlabels? Just change the only textlabel to the LocalPlayer
’s username?
2 Likes
I actually have. In the 2nd line of the local script it says here:
local PlayerNameText = script.Parent.PlayerNameText
2 Likes
You’re changing that TextLabel
’s text to the LocalPlayer
’s username and not creating a new label like this:
game.ReplicatedStorage.CreateServers.CreateServerPlayer.OnClientEvent:Connect(function(plr)
local label = PlayerNameText:Clone()
label.Text = plr.Name
label.Parent = script.Parent
end)
3 Likes
Oh Yes! I didn’t think much about that. Though I am not quite sure why you cloned the PlayerNameText. Can you explain why?
As you can see in this picture it leaves the “PlayerName” text alone which should’ve been replaced by the “planeboy2021” text label.
1 Like
@remcodesremcodes
Ok, I have tested through different clients. And here is what I got:
This is screen of the player who joined the server:
- Still don’t know why you have added clone
- The server creator’s name is there
- The player’s name who joined the server is not there
I am pretty sure it is from this local script (the script from the main post)
I also think the problem is from the first and fourth remote.
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:Clone()
label.Text = plr.Name
label.Parent = script.Parent
end)
game.ReplicatedStorage.PLRNames.OnClientEvent:Connect(function(plrname)
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)
1 Like
I’m slightly confused, which players do you want to pop up? All players except the creator?
1 Like
I clone it so that instead of replacing the same label for each player (which gets nowhere), it adds a new one joined by the UIListLayout
with the new name.
1 Like
So I want everyone in the lobby to be able to see who’s in the lobby with those text labels.
I am going to sleep in a few minutes. I will reply to this comment when I do wake up. My timezone is AEST.
1 Like
So, in other words, everyone that isn’t in a server? Is that what you mean?
1 Like
Im not quite sure… but probably.
A player creates a server, they are the server creator. Then it adds a textlabel with the text as their username. People can then join their server with a serverID (a 5 number randomised code) once they join, it clones the textlabel and sets the text as their name.
I want everyone in that server to be able to see all of the text labels. But, only the player can see their own text label.
1 Like
@remcodesremcodes I am awake and ready to work.