Hello!!
I am trying to change some ui elements when a Remote function gets invoked. I have also added a print statement to a serverscript when it calls the Remote function, however the print statement does not get printed. Furthermore it sends me this warning with it.
“Failed to create server” I have been trying to trouble shoot this for this whole day, but nothing has succeeded.
I have narrowed the problem down to three scripts, one server and two local scripts.
Here are them.
Local script that changes ui elements.
local ScreenGUI = script.Parent
local Players = game:GetService("Players")
local CreateBTN = ScreenGUI.ServerSelect.CreateServer
local ServerIDNum = ScreenGUI.Server.CreaterPanel["Server ID"].SERVERIDNumber
local ServerName = ScreenGUI.Server.ServerName
ScreenGUI.Server.CreaterPanel.Visible = false
CreateBTN.MouseButton1Click:Connect(function()
local ServerID = game.ReplicatedStorage.CreateServer:InvokeServer()
if ServerID then
print("Created server with ID:", ServerID)
ScreenGUI.Server.Position = UDim2.new(0.5, 0,0.365, 0)
ScreenGUI.ServerSelect.Visible = false
ScreenGUI.Server.CreaterPanel.Visible = true
ScreenGUI.Server.Visible = true
ServerIDNum.Text = ServerID
ServerName.Text = Players.LocalPlayer.Name .. " 's SERVER"
else
warn("Failed to create server")
end
end)
ServerScript which the print statement does not get printed. (“CreateServer”) - Print statement
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)
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.. "'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
ReplicatedStorage.CreateServer.OnServerInvoke = function(player)
ReplicatedStorage.CreateServerPlayer:FireAllClients(player)
end
ReplicatedStorage.JoinServer.OnServerInvoke = function(player)
ReplicatedStorage.JoinServerPlayer:FireAllClients(player)
end
Local script which might cause the issue:
local Players = game:GetService("Players")
local PlayerNameText = script.Parent.PlayerNameText
game.ReplicatedStorage.CreateServerPlayer.OnClientEvent:Connect(function()
print("recieved")
PlayerNameText.Text = Players.LocalPlayer.Name
end)
game.ReplicatedStorage.JoinServerPlayer.OnClientEvent:Connect(function()
local playerTextClone = PlayerNameText:Clone()
playerTextClone = Players.LocalPlayer.Name
playerTextClone.Parent = script.Parent
end)