In this example, you can see the server and the join it button, as well as the 0/25 label, I would like it to display how many players are on the Project Marus Official 1 server. Since I don’t even know how to do this, I want to ask for help on the forum…
When ever a play joins the server have it fire a remote to all clients to add one to the amount of players and if they leave remove one. One way you could go about this is
player clicks join > Fire Server > Add them to server and increase player count > Fire All Clients
In the server you would add one and add them to the server that part is up to you but once that is all done make sure to update all the clients.
I can’t imagine how to do it, can you help?
So this is a really basic way of doing it and you will need to add to it.
-- Client Side (localscript)
local JoinButton = -- Path to join button
local RemoteEvent = -- Path to remote event
JoinButton.Activated:Connect(function() -- Join Button Pressed
RemoteEvent:FireServer("Server 1") -- Send the server they pressed to server
end)
-- This RemoteEvent will connect when the server has fired to all clients
RemoteEvent.OnClientEvent:Connect(function(server : string, amount : number)
-- Change amount of player text here
-- It would look something like this: [path.to.text].Text = amount.."/25"
end)
That should be the client side done. As you can see we are using the same remote to communicate between the server and client. I’m not sure if there are any downsides to doing this but this is what I would do.
-- Server Side (script or modulescript)
local RemoteEvent = -- Path to Remote Event
local Servers = { -- Create a table for servers
["Server 1"] = {}, -- You could change this to a number but you would want to store players in here I'm assuming
}
-- This functions just adds all the players up and returns the amount of players
local function GetPlayerCount(Server : string) : number
local Amount = 0
for _, player in ipairs(Servers[Server]) do
Amount += 1
end
return Amount
end
RemoteEvent.OnServerEvent:Connect(function(player : player, server : string)
-- Add some checks to see if player exist incase the client is exploiting
if Servers[server][player] then return end -- They are already apart of it
table.insert(Servers[server], player) -- Adds player to the server table
RemoteEvent:FireAllClient(Server, GetPlayerCount(server)) -- Update all the clients
end)
Hopefully this helps
I’d ditch the effort to do it server-sided as it’s just a label and do the PlayerAdded
on a LocalScript.
It’s not that complicated. One local script and you’re done. You just have to update the PlayerCount text when a player entered or left the game.
local Players = game:GetService("Players")
local PlayerCount = script.Parent
local function UpdatePlayerCount()
PlayerCount.Text = #Players:GetPlayers() .. "/25"
end
Players.PlayerAdded:Connect(UpdatePlayerCount)
Players.PlayerRemoving:Connect(UpdatePlayerCount)
Yeah but I think they are going to have multiple servers so if the servers are handled on the server then the client will always get the correct amount of players also if they want the players to be teleported then it will have to be done on the server. You could use PlayerAdded but then you also need to know which server a player joins, this is of course if they’re using multiple servers which I’m unsure about.
Where do I specify the Id of the place where the player will go?
If you want player count of a vip server then store the vip server code, and player count in datastore.
You would define that in a server script. In the example I gave you I haven’t done that since it was made clear but when your ready to teleport player you would loop through the Servers table and teleport them. I believe you can send a table of players so you could just send the Servers Table instead of looping through. I would look into teleport service to see how it works.
local function GetPlayerCount(server : string) : number
local amount = #Servers[Server]
return amount
end
Of course, this is the basic version and you do need to add to it but in theory, it should work. Like @Synitx said instead of looping through the entire table you could get the length of the table instead. Not sure exactly why I did it that way but do be sure to change that.
You could also remove the function completely and just change Event arguments like this: RemoteEvent:FireAllClients(server, #Servers[server])
Well, what is there now that I have done everything, the system should work?
I don’t really understand this system could you make the player teleport just before I just did the GUi and the teleport button and now I don’t know how to do something here
As long as you have defined all the paths and everything it should work. This is only for changing the number so this won’t actually teleport anyone.
Unfortunately, I can’t just give you an entire script but what I would do is when the Server is ready to send players whether that is a timer or when the server is full. You would get all the players currently in the server and use TeleportService
to send the players to your desired place
As far as I understand you, should I write in an empty line so that the player is teleported? this is a local script
You shouldn’t handle teleporting in a client script. You should just add it into the server script.
I’m not really fimilar with teleport since I haven’t used it but looking through the Developer Hub on TeleportService it looks fairly straightforward.
local TeleportService = game:GetService("TeleportService")
local PlaceID = -- Enter ID here
-- When your ready to teleport
TeleportService:TeleportPartyAsync(PlaceID, {tableOfPlayers})
If this isn’t correct I’m sure someone will help.