I knew about that, I believe you misread what I said, I needed help with the joining a running server portion, not the dying. Thanks though! It’s understandable!
Yup so, I think this is all I need right now, but if you don’t understand something, just please tell me, I’d be happy to answer your questions!
Heya. Sorry for the slightly slow response, I had to go and teach myself a little MessagingService
Here’s some example code, and some descriptions from the wiki.
To summarize, send a message with a “key” like this:
MessagingService:PublishAsync(string topic, Variant message)
And listen for a specific key like this:
MessagingService:SubscribeAsync(string topic, Function callback)
For some reason, I found the data passed when subscribing is passed in a dictionary with the actual data and the time it was sent. Here’s an example which I wrote, and it works (in real servers, MessagingService doesn’t work into studio yet)
Example:
local msgService = game:GetService("MessagingService")
print("subscribing")
msgService:SubscribeAsync("Test", function(value) -- listen for a message
print("recieved test message, message is " .. value["Data"] .. " and it was sent at " .. value["Sent"])
end)
local function plrAdded(player)
wait(5)
print("publishing")
msgService:PublishAsync("Test", player.Name) -- send the player's name as a message with the same key
end
game.Players.PlayerAdded:Connect(plrAdded) -- player joins
for _,player in next, game.Players:GetPlayers() do -- just incase a player already joined
plrAdded(player)
end
This example is listening for a message, which it also sends when a player joins (so the server listens for it’s own message, which is a bit silly). But of course in a real scenario you would send message and receive them from different servers.
It works in a single server, but can also be used in multiple server structures like yours
Hey there! That’s understandable. I’m going to try editing that system to make a multi-server base. Thanks for the help! I’ll let you know how it ends up!
Awesome! Don’t forget to mark someone’s response as the solution, mine or someone else’s
Why are you using an IntValue? Just have a PlayersIngame variable in the script.
I meant to reply to @Kensizo sorry!
Hey there, one question:
Would this work if I had your example exactly, however I added a Teleport function in when it senses a player is added? (It will wait for 1 second over and over again until 10 players join, then it’ll start the script?)
Uhh… not sure exactly what you mean, sorry. Teleport when it senses a player has been added??
This seems like a good way to structure the cross server messages. There’s no point in using a loop to check the player count in the private servers if you can check it when a player joins instead.
When a player joins check if the count is 10, if so start the game and send a message to the main server. When a player leaves check the count is 0, if so send a message to main server. When a player dies send them back to the main hub. This should work fine, but feel free to ask again if I just got a little confused.
Ok so here’s what I think you mean by the, “There’s no point in using a loop to check the player count in the private servers if you can check it when a player joins instead.”
game.Players.Playeradded:Connect(function(player)
if #game.Players:GetPlayers() == 10 then
game:GetService("TeleportService"):Teleport(PLACEID, player)
end
end)
This will teleport only the 10th player to a different server which I’m not sure is what you want… is this in the main server or the private one?
This would be in the Map, then it would TP the player to the hub. What do you mean by it would TP the 10th player?
You could do this in the private servers, but people can’t join private servers unless the hub specifically sends them to it. If you’re using messaging service and tell the hub when the private server is full, then just don’t send players to that server anymore (make a new one) and this should work fine. You could check if the number of players is more than a certain number when a player joins but then players will just be being teleported back and forth between servers!
So wait, is this system kind of how games like Eviction Notice and Survivor code their matchmaking? I’m just trying to figure out the similarities, and because I find their system never bugs up or anything. Sorry for asking so many questions.
One more question, how can I create/check for private servers and their player counts?
This is where the messaging service comes in; by sending each private servers player count to the main hub, the hubs can check which servers are available and therefore decide whether they should create a new private server or send the player to an existing server, using TeleportService.
I ran through the layout of the code on this post:
Ok, so I’m curious, I’m kind of clueless right now, with multiple things:
- I don’t really understand the concept of MessagingService, and how to Message other servers.
- I don’t know how to make a Private Server.
Sorry, I’m just not getting it right now. If you want to try explaining it again, you can, if not, that’s fine too.
Okay, well you’ll have to do a little bit of your own research too, and once you have researched a bit have a go at making this system that we’ve discussed!
MessagingService means you can broadcast a message and listen for messages. Imagine someone shouting, but only a select few people are listening for their shout.
In the same way, a server can “shout” something by calling MessagingService:PublishAsync(), and any servers that are “subscribed” (listening) for that shout will run the function associated. They can listen for a shout with the method MessagingService:SubscribeAsync().
This is useful because you can “shout” things with a specific key, such as a name, and then include information sent along with the shout. If a server is listening for the shout with that specific key, it can run a function and use the extra data sent along with it.
In my example earlier, one server listens for the shout with the key “Test”, and will print the data that gets sent with that shout. The other server sends a shout with the key “Test” and the extra data of the players name when a player joins. Therefore the first server gets a message with the data being the player’s name from the other server.
More info about MessagingService, Using MessagingService: a community tutorial and the developer hub: Messaging Service.
Check out the developer forum on sending players to private servers etc; TeleportService API page, ReserveServer Method and TeleportToPrivateServer Method.
Let me know if you need any other help, but you should be able to start off using TeleportService and MessagingService after looking at these pages or elsewhere on the forum (maybe there are more tutorials, if I didn’t find them). Hope it all goes well!
Alright well, I’m going to take a quick break, just clear my mind a bit, then I’ll come back and research some stuff, and get back to you, sounds good? Thanks so so so so so so so much for the help today!
Hey there! So while experimenting and researching, I came up with an idea: I could just teleport the player with a loading screen that says that the server was full! Thanks for the help, but I ended up needing just to stop and think! Sorry about the waste of time, and I’ll let you know if I need anything else.
I don’t see why you’d create a “Numb” value when you could easily just do #game.Players:GetChildren()