Here when the player joins it does fire a remote event
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
Which is called from our local script:
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
-- InServer = false
end
end
print(InServer)
end)
So do I make a new remote event, then where do i put the code in that local script.
I don’t understands why it don’t add the player2 to player 1 but lets try debug:
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
for i, player in pairs(game.Players:GetPlayers()) do
if not script.Parent:FindFirstChild(player.Name) then
warn("Adding player: " .. player.Name .. " to the list for local user: " .. game.Players.LocalPlayer.Name)
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
-- InServer = false
end
end
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 and not script.Parent:FindFirstChild(plrname) then
warn("Adding player: " .. plrname .. " to the list for local user: " .. game.Players.LocalPlayer.Name)
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)