PlayerNameText is the texlabel i want to clone.
Ye sure clone that to the ui it needs like you do after firing to all clients and a line after firing do that in the StarterGui
Ok! What do I do next? (Filling character limit)
Can you please put that in code form since it is hard to understand.
What’s your code what clones it
What do you mean by (Filling character limit) ?
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
PlayerName = plrname
InServer = false
else
print("Player is not in server")
end
end)
Here is the full script:
local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText
local myServerName
local InServer = false
local PlayerName = ""
game:GetService("ReplicatedStorage").JoinServers.JoinServerPlayer.OnClientEvent:Connect(function()
InServer = true
for i, player in pairs(game.Players:GetPlayers()) do
if not script.Parent:FindFirstChild(player.Name) then
local playerTextClone = PlayerNameText:Clone()
playerTextClone.Text = player.Name
playerTextClone.Parent = script.Parent
playerTextClone.Name = player.Name
--PlayerName = plrname -- Don't understands what is this for
InServer = false
end
end
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
PlayerName = 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)
Since you have to put atleast 30 letters to send the reply
So just also why you set InServer = false? Try with this code:
local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText
local myServerName
local InServer = false
local PlayerName = ""
game:GetService("ReplicatedStorage").JoinServers.JoinServerPlayer.OnClientEvent:Connect(function()
InServer = true
for i, player in pairs(game.Players:GetPlayers()) do
if not script.Parent:FindFirstChild(player.Name) then
local playerTextClone = PlayerNameText:Clone()
playerTextClone.Text = player.Name
playerTextClone.Parent = script.Parent
playerTextClone.Name = player.Name
-- PlayerName = plrname -- Don't understands what is this for
-- InServer = false
end
end
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
PlayerName = 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)
-- add after firing the remote event to all clients
task.wait(0.1)
if InServer == true then
print(tostring(plrname))
local playerTextClone = game.startergui.servergui.server.players.textlabel:Clone()
playerTextClone.Text = tostring(plrname)
playerTextClone.Parent = game.startergui.<path to parent>
playerTextClone.Name = plrname
PlayerName = plrname
InServer = false
else
print("Player is not in server")
end
I don’t know how you get the is in server but add that also to the server script
InServer is when the player joins the server so:
- Player is not in a server, InServer = false
- Player joins a server, InServer = true
Then make sure to add if they not in server on the StarterGui and all clients to remove the name but just do the same as you do on all clients to the startergui too
You also can add another remote event to the server after the client added the name to do so but idk how exactly is inserted is handled
Ye I have, when the player leaves the server it removes the text label unless they are the server creator, and sets InServer to false
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)
InServer = false
PlayerTextClone:Destroy()
end
end)
Just make sure you do the same on StarterGui as new players get that ui
I dont know what hapened but on the player who joined screen the text labels duplicated
Server Creator:
Player who joined:
By inserted to you mean InServer?
Maybe you can fire another remote as the player joins to the server then in StarterGui clone a label with Thier name and when leave also clear it in StarterGui
Yeah, but would you still able to see the text labels on all screens?
Ye if you do fire all clients all clients get the label on screen but new players don’t get that labels what already exists