Hello!!!
I have made two scripts, a server and local script.
I want to make so when the local script receives a remote function, it changes the ServerName (textlabel) to player.Name:
What it looks like right now:
What its supposed to look like:
Dont mind about the blue outline
In the serverscript, I donāt know where to put the
RemoteFunction:InvokeClient.
without disrupting the script.
I want it to be when the player creates the server it, the sends the remote function to the client. (Remote function for player creating server[ is called CreateServer) (Remote function for sending it to the client is called CreateServerPlayer)
Now when the player joins the server, it recieves a remote function, then I want it to send a remote function to the client, where it then clones the textlabel(PlayerName) and change the text to the player.Name who joined the server. (Remote function for player joining server is called JoinServer) (Remote function for sending it to the client is called JoinServerPlayer)
Here are the full scripts: (add to serverscript so it sends both remote functions to the client)
serverscript:
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.Name, 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
Local script
local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText
game.ReplicatedStorage.CreateServer.OnClientInvoke = function(player)
print("recieved")
PlayerNameText.Text = player.Name
end
game.ReplicatedStorage.JoinServerPlayer.OnClientInvoke = function(player)
PlayerNameText:Clone()
PlayerNameText.Text = player.Name
end