I have made two scripts, a local and server script.
In the server script, it makes a string value in ServerScriptService.ServerIDHandler(the server script).ServerNames.
The string value.value is the names of the server’s e.g (planeboy2021’s SERVER)
Then it invokes a remote function to the local script with the parameters, player, ServerName.
local ServerName = Instance.new("StringValue")
ServerName.Name = player.Name.. "'s SERVER"
ServerName.Value = player.Name.. "'s SERVER"
ServerName.Parent = ServerScriptService.ServerIDHandler.ServerNames
-- set the parent as the last property because it's more optimized
game:GetService("ReplicatedStorage").ServerNames:InvokeClient(player, ServerName.Value)
This works fine.
In the local script, it takes that information and changes the serverName.text to the ServerName.value
local player = game:GetService("Players")
local ServerGui = script.Parent
local ServerName = ServerGui.Server.ServerName
game:GetService("ReplicatedStorage").ServerNames.OnClientInvoke = function(PlayerServerName)
print(PlayerServerName)
ServerName.Text = PlayerServerName
end
However, when I played with two clients, for player 1 which created the server worked fine, but for player two which joined the server, the ServerName still said “SERVER NAME”
Are all players meant to see the same text in the textlabel, at all times? Or will it be possible for players to view different text than what another player is seeing
You need to send the player receiving the Invoke signal as an argument, but since only the server owner player is sent, the signal only goes to that player.
So, use for loop to give both two players a signal.
for _, ReceivePlayer in ipairs(game.Players:GetPlayers()) do
game:GetService("ReplicatedStorage").ServerNames:InvokeClient(ReceivePlayer, player, ServerName.Value)
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.CreateServer.OnServerInvoke = function(player)
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.. "'s SERVER"
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:InvokeClient(ReceivePlayer, player, ServerName.Value)
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.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)
return true
end
end
warn(player.Name .. " failed to join server with ID:", ServerID)
return false
end