I have made a script where it creates a new string value instance where its value is the player’s name and … " 's Server" I have also made it so, it invokes a remote function.
In my local script, I say when it recieves that remote event it prints out the ServerName. However it prints out nil.
local player = game:GetService("Players")
local ServerGui = script.Parent
local ServerName = ServerGui.Server.ServerName
game.ReplicatedStorage.ServerNames.OnClientInvoke = function(player, ServerName)
print(ServerName)
end
You don’t need to include the player argument. The purpose of passing the player argument in the server was so that the game knew where to fire the RemoteFunction to. Simply emit the player argument here and you should be alright
local player = game:GetService("Players")
local ServerGui = script.Parent
local ServerName = ServerGui.Server.ServerName
game.ReplicatedStorage.ServerNames.OnClientInvoke = function(PlayerServerName)
print(PlayerServerName.Value)
end
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)
local player = game:GetService("Players")
local ServerGui = script.Parent
local ServerName = ServerGui.Server.ServerName
game:GetService("ReplicatedStorage").ServerNames.OnClientInvoke = function(PlayerServerName)
print(PlayerServerName)
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
game:GetService("ReplicatedStorage").ServerNames:InvokeClient(player, ServerName.Value)
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)
game.ReplicatedStorage.ServerNames:InvokeClient(player)
return true
end
end
warn(player.Name .. " failed to join server with ID:", ServerID)
return false
end
It was the issue, I just removed the line and now it works!
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)
game.ReplicatedStorage.ServerNames:InvokeClient(player) -- This Line
return true
end
end
warn(player.Name .. " failed to join server with ID:", ServerID)
return false
end