-
What do you want to achieve?
For the Player who joined to see all player’s and for all player’s to see who is in the server. -
What is the issue?
This image is the player who joined, He can only see him in the server and no one else (There is another person because that’s who created it)
And this is the server owner (person who created it) You can notice that everyone in the server is there.
A weird thing I found while using the GetPlayersInServer() function is working right. It has all the players in the server, so it’s something to do with the JoinServer’s for loop.
3. What solutions have you tried so far?
I have tried respricting the entire function but still doesn’t work. I tried asking others for help but they ghosted the post after 1-2 replies.
function MainModule.JoinMultiplayerServer(UneededTable : nil, Player : Player, ServerNum : number)
local PlayersService = game:GetService("Players")
local ServerStorageService = game:GetService("ServerStorage")
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local ServerFolder = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
local PlayerFolder = Instance.new("Folder", ServerFolder.Players)
PlayerFolder.Name = tostring(Player)
local OwnerPlayer = Instance.new("ObjectValue", PlayerFolder)
OwnerPlayer.Name = "Player"
OwnerPlayer.Value = Player
Player.PlayerGui.MainUI.ServerOwner.Visible = true
local ServerTable = ServersSetting[tostring(MainModule:GetOwnerFromMultiplayerServer(ServerNum)).."Server"]
local ServerInfoTable = ServersSetting[tostring(MainModule:GetOwnerFromMultiplayerServer(ServerNum)).."ServerInfo"]
ServerTable.AmountOfPlayersInServer += 1
Player.PlayerGui.MainUI.ServerOwner.OptionsFrame.BanPlayers.Text = ServerInfoTable["BanPlayers_"..tostring(ServerTable.BanPlayers)]
local PlayersInServer = MainModule:GetPlayersFromMultiplayerServer(ServerNum)
for index, value in pairs(PlayersInServer) do
local ServerOwnerClone = ServerStorageService.UIStuff.Junk.ServersUI.PLAYERNAME:Clone()
ServerOwnerClone.Name = tostring(Player)
ServerOwnerClone.Parent = value.PlayerGui.MainUI.ServerOwner.PlayersFrame
end
end
Full Code Here
local MainModule = {}
local ServersSetting = {}
function MainModule.EnableUI(UneededTable, player : Player, UIName)
if player.ClassName ~= "Player" then warn("Not a valid player!") return end
local FindMainUI = player.PlayerGui:FindFirstChild(tostring(UIName))
if FindMainUI and FindMainUI:IsA("ScreenGui") then
player.PlayerGui.MainUI.Enabled = true
local FindMainFrame = FindMainUI:FindFirstChild("MainFrame")
if FindMainFrame and string.find(FindMainFrame.ClassName, "Frame") then
FindMainFrame.Visible = true
end
end
end
function MainModule.DisableUI(UneededTable, player : Player, UIName)
if player.ClassName ~= "Player" then warn("Not a valid player!") return end
local FindMainUI = player.PlayerGui:FindFirstChild(tostring(UIName))
if FindMainUI and FindMainUI:IsA("ScreenGui") then
player.PlayerGui.MainUI.Enabled = false
end
end
function MainModule.CheckIfValueIs(UneededTable : nil, Object, CheckIfIsA)
local IsA = false
local Success, FailMessage = pcall(function()
if type(Object) == tostring(CheckIfIsA) or typeof(Object) == tostring(CheckIfIsA) or Object:IsA(CheckIfIsA) then
IsA = true
else
warn(type(Object), typeof(Object))
end
end)
if Success and IsA then
return true
else
return false
end
end
function MainModule.RetrieveFrameUI(UneededTable : nil, Player : Player, ScreenGuiName : string, FrameName : string)
local CheckIfPlayerIsAPlayer = MainModule:CheckIfValueIs(Player, "Player")
if CheckIfPlayerIsAPlayer == true then
local FindScreenUI = Player.PlayerGui:FindFirstChild(ScreenGuiName)
if FindScreenUI then
local FindFrameUI = FindScreenUI:FindFirstChild(FrameName)
if FindFrameUI then
return FindFrameUI
end
end
else
warn(tostring(Player), "Is not a valid player!")
end
end
function MainModule.GetPlayersFromMultiplayerServer(UndeededTable : nil, ServerNum : number)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local FindServer = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
local Players = {}
for index, object in ipairs(FindServer.Players:GetChildren()) do
table.insert(Players,object.Player.Value)
end
print(#Players)
for index, object in ipairs(Players) do
print(index, object)
end
return Players
end
function MainModule.GetOwnerFromMultiplayerServer(UneededTable: nil, ServerNum: number)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local FindServer = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
for index, object in ipairs(FindServer.Players:GetChildren()) do
if object:GetAttribute("IsOwner") == true then
return object
end
end
end
function MainModule.CreateMultiplayerServer(UneededTable : nil, Player : Player)
print(Player)
local PlayersService = game:GetService("Players")
local ServerStorageService = game:GetService("ServerStorage")
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local GetPlayers = PlayersService:GetPlayers()
ServersSetting[tostring(Player).. "Server"] = {
ServerNum = 0,
BanPlayers = false,
GameDiff = 1,
MaxPlayers = 4,
GameMode = 1,
AmountOfPlayersInServer = 1,
BannedPlayers = {}
}
ServersSetting[tostring(Player).."ServerInfo"] = {
BanPlayers_true = "Ban Players from Sever (Instead of kicking) Status: Enabled",
BanPlayers_false = "Ban Players from Sever (Instead of kicking) Status: Disabled"
}
for index, UI in ipairs(Player.PlayerGui.MainUI:GetChildren()) do
UI.Visible = false
end
Player.PlayerGui.MainUI.ServerOwner.Visible = true
local ServerFolder = ReplicatedStorageService.ServersInfo.Templates.ServerNUMBER:Clone()
ServerFolder.Parent = ReplicatedStorageService.ServersInfo.Servers
local AmountOfSevers = #ReplicatedStorageService.ServersInfo.Servers:GetChildren()
ServerFolder.Name = "Server"..AmountOfSevers
ServersSetting[tostring(Player).."Server"].ServerNum = AmountOfSevers
local OwnerFolder = Instance.new("Folder", ServerFolder.Players)
OwnerFolder.Name = tostring(Player)
OwnerFolder:SetAttribute("IsOwner", true)
local OwnerPlayer = Instance.new("ObjectValue", OwnerFolder)
OwnerPlayer.Name = "Player"
OwnerPlayer.Value = Player
ServerFolder:SetAttribute("Owner", tostring(Player))
warn(ServerFolder.Parent)
for index, PlayerObject in ipairs(GetPlayers) do
local ServersUI = PlayerObject.PlayerGui.MainUI.Servers
local CreateServerJoinUI = ServerStorageService.UIStuff.Junk.ServersUI.Server:Clone()
CreateServerJoinUI.Parent = PlayerObject.PlayerGui.MainUI.Servers.ServersFrame
CreateServerJoinUI.Name = "Server"..ServersSetting[tostring(Player).."Server"].ServerNum
CreateServerJoinUI:SetAttribute("ServerNum", ServersSetting[tostring(Player).."Server"].ServerNum)
CreateServerJoinUI.Text = "Sever "..ServersSetting[tostring(Player).. "Server"].ServerNum.." - Players "..ServersSetting[tostring(Player).. "Server"].AmountOfPlayersInServer.. " / " ..ServersSetting[tostring(Player).. "Server"].MaxPlayers
end
for index, player in ipairs (MainModule:GetPlayersFromMultiplayerServer(ServersSetting[tostring(Player).."Server"].ServerNum)) do
local OwnersFrameClone = ServerStorageService.UIStuff.Junk.ServersUI.PLAYERNAME:Clone()
OwnersFrameClone.Name = tostring(Player)
OwnersFrameClone.Text = tostring(Player)
OwnersFrameClone.Parent = player.PlayerGui.MainUI.ServerOwner.PlayersFrame
end
end
function MainModule.JoinMultiplayerServer(UneededTable : nil, Player : Player, ServerNum : number)
local PlayersService = game:GetService("Players")
local ServerStorageService = game:GetService("ServerStorage")
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local ServerFolder = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
local PlayerFolder = Instance.new("Folder", ServerFolder.Players)
PlayerFolder.Name = tostring(Player)
local OwnerPlayer = Instance.new("ObjectValue", PlayerFolder)
OwnerPlayer.Name = "Player"
OwnerPlayer.Value = Player
Player.PlayerGui.MainUI.ServerOwner.Visible = true
local ServerTable = ServersSetting[tostring(MainModule:GetOwnerFromMultiplayerServer(ServerNum)).."Server"]
local ServerInfoTable = ServersSetting[tostring(MainModule:GetOwnerFromMultiplayerServer(ServerNum)).."ServerInfo"]
ServerTable.AmountOfPlayersInServer += 1
Player.PlayerGui.MainUI.ServerOwner.OptionsFrame.BanPlayers.Text = ServerInfoTable["BanPlayers_"..tostring(ServerTable.BanPlayers)]
local PlayersInServer = MainModule:GetPlayersFromMultiplayerServer(ServerNum)
for index, value in pairs(PlayersInServer) do
local ServerOwnerClone = ServerStorageService.UIStuff.Junk.ServersUI.PLAYERNAME:Clone()
ServerOwnerClone.Name = tostring(Player)
ServerOwnerClone.Parent = value.PlayerGui.MainUI.ServerOwner.PlayersFrame
end
end
function MainModule.RetrieveMultiplayerSettings(UneededTable : nil, ServerNum : number)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local FindServer = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
if FindServer then
MainModule:GetPlayersFromMultiplayerServer(ServerNum)
end
end
function MainModule.UpdateSettings(UneededTable : nil, Owner : Player, SettingName)
local FindSettingTable = ServersSetting[tostring(Owner).."Server"]
if FindSettingTable then
if SettingName == "BanPlayers" then
FindSettingTable.BanPlayers = not FindSettingTable.BanPlayers
local PlayersInServer = MainModule:GetPlayersFromMultiplayerServer(FindSettingTable.ServerNum)
for index, player in ipairs(PlayersInServer) do
if FindSettingTable.BanPlayers == true then
player.PlayerGui.MainUI.ServerOwner.OptionsFrame.BanPlayers.Text = "Ban Players from Sever(Instead of kicking) Status: Enabled"
else
player.PlayerGui.MainUI.ServerOwner.OptionsFrame.BanPlayers.Text = "Ban Players from Sever(Instead of kicking) Status: Disabled"
end
end
end
end
end
function MainModule.KickPlayer(UneededTable : nil, ServerNum: number, PlayerToKick : Player, Kicker : Player)
local ReplicatedStorageService = game:GetService("ReplicatedStorage")
local PlayersService = game:GetService("Players")
local FindServer = ReplicatedStorageService.ServersInfo.Servers:FindFirstChild("Server"..ServerNum)
if FindServer then
local FindPlayer = FindServer:FindFirstChild(tostring(PlayerToKick))
if FindPlayer then
local Owner = PlayersService:FindFirstChild(tostring(FindServer:GetAttribute("Owner")))
end
end
end
return MainModule