How would I use the ui in startergui in the server, aren’t ui only work on the client side?
I’m not sure but probably you can access startergui on the server since the client ui is the player Gui if that don’t work make in ReplicatedStorage the maximum for the names and do the same as firing all clients after receiving and when a new player joins clone the main ui from repli but I’m pretty sure startergui can be modified from server that’s what being replicated to the client into player Gui that only client can acces
To be honest, I don’t know man my last resort is to have you in my game with me.
I have no idea how to access starter gui on the server.
- What do you mean maximum for the names
- And do what the same?
- I just want to clone the text label not the whole thing
You may be using FireAllClients
, but where is the LocalScript that listens for this event?
Here is the local 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
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)
On the server script do
--server
local SG = game:GetService("StarterGui")
task.wait(0.1)
if InServer == true then -- idk if this already is in server script
print(tostring(plrname))
local playerTextClone = PlayerNameText:Clone()
playerTextClone.Text = tostring(plrname)
playerTextClone.Parent = SG.--(path to parent to clone name to)
playerTextClone.Name = plrname
PlayerName = plrname
InServer = false
else
print("Player is not in server")
end
If you do the same for StarterGui when a new player joins they get ui with that changed things cuz it’s replicated from StarterGui on join
Here is the server script:
Where do I put this
I am a bad scripter and don’t want to mess it up
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:FireAllClients(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
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
ReplicatedStorage.CreateServers.CreateServerServer.OnServerEvent:Connect(function(player)
ReplicatedStorage.CreateServers.CreateServerPlayer:FireAllClients(player)
end)
ReplicatedStorage.CloseFunction.CloseServerUI.OnServerEvent:Connect(function(player)
ReplicatedStorage.CloseFunction.LeaveServer:FireAllClients(player)
end)
The problem is that you don’t take the names of players who were already in the game.
So, how would I do that? (Filling character limit)
Just apply what you do when fireallclients to the StarterGui too as new players get that ui
Doesn’t it get the player’s name already?
for _, ReceivePlayer in ipairs(game.Players:GetPlayers()) do
game:GetService("ReplicatedStorage").ServerNames:FireAllClients(ReceivePlayer, player.Name, ServerName.Name)
print("for loop")
end
Ye but if a new player joins they get the state from StarterGui so they only see Thier own name
What do you mean by the state?
StarterGui is like a template to clone when a player joins so there no names there when a new player joins
So how would I overcome this??
Modify the StarterGui also with clone the names there on the server script
Do you mean StarterGui as game.StarterGUI or ServerGui?
Game.startergui and then the object ui you want to clone the names to
In your local script you can just retrieve the name of all the players.
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
end
end
print(InServer)
end)