Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I use HttpService for this?

Asked by 7 years ago
Edited 7 years ago

How would I use HttpService to find and display roblox server list?

P.S: First time using SH

0
Not possible unless using a proxy. Might I suggest using DataStores to provide JobIds of servers of the game you're creating and have that determine if a session is running or not. M39a9am3R 3210 — 7y
0
Thats a good idea actually, I'll try it out. Thanks FantasyStudios 0 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

To expand upon M39a9am3R's comment (again, sorry):


It really isn't that hard, once you think about it. But, if you are not DataStore savvy, here is how you do it:

STEP 1:

What this guide teaches you how to create is basically multiple tables within tables, with each of the individual tables being servers, with their values being all of the server's player's ids/usernames.

Set up your DataStore, by simply doing this:

local ds = game:GetService("DataStoreService"):GetDataStore("ServerList")
local key = "servers" -- for later use
local serverId = "" -- will get on to generating later
local server = {}

-- server id generation here

-- player handling here

local curData = ds:GetAsync(key) or {} -- gets the data
cur[serverId] = server -- adds in the server
ds:UpdateAsync(key,curData) -- updates, UpdateAsync because multiple servers could be doing this at the same time

Check out the DataStore wiki page if you're unsure about any of this; and ask for any help you need (I can't link to wiki, sorry, school internet blocks ROBLOX websites :P).

STEP 2:

When a player joins/leaves, you want to update the server list, so put the following code into the player handling area:

game.Players.PlayerAdded:connect(function(p) -- when a player joins
    server[p.Name] = p.UserId -- sets their value
    local curData = ds:GetAsync(key) or {} -- gets data
    curData[serverId] = server -- updates server data
    ds:UpdateAsync(key,curData) -- update DataStore
end)

game.Players.PlayerRemoving:connect(function(p) -- when a aplayer leaves
    server[p.Name] = nil -- deletes the value from the table
    local curData = ds:GetAsync(key) or {}
    curData[serverId] = server
    ds:UpdateAsync(key,curData)
end)

STEP 3:

Server Id generation is something different, but I will provide an example (put code in serverid generation area):

serverId = math.random(1000,9999).. "_server_" ..math.random(1,1000) -- pretty basic, really

You should be set after this! To get all of the servers, just iterate through the main table.


Hopefully this helped!

~TDP

Ad

Answer this question