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

How can I check if a random player on roblox who is not in game is in a group?

Asked by 5 years ago

So I want to make kinda like a player group check thing, where players can check if other players are in a group or not. If that player was in a group, you could use :IsInGroup, but this does not allow that since the player is not in the game. Is there any way to check if a random player on roblox is in a group using only their name or userid?

0
[https://developer.roblox.com/api-reference/function/Player/IsInGroup](https://developer.roblox.com/api-reference/function/Player/IsInGroup) this should be of use for you CardJester 15 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Update: I completely forgot GroupService existed. You can use GroupService:GetGroupsAsync() to make this happen without using HttpService.

local GroupService = game:GetService("GroupService")

local GroupId = 0
local PlayerId = 0
local PlayerIsInGroup = false

for _, group in ipairs(GroupService:GetGroupsAsync(PlayerId)) do
    if group.Id == GroupId then
        PlayerIsInGroup = true
        break
    end
end

if PlayerIsInGroup then
    -- Do something
else
    -- Do something else
end

-- Old answer -- A way to accomplish this could be using HttpService to contact the Roblox web API, but unfortunately HttpService blocks requests that attempt to access any sub-domain on roblox.com.

Luckily, there is a workaround to this problem. You could use HttpService to send a request to a website (or another API) that handles the request on their backend then return the value given by the Roblox API, but this involves using a different programming language other than Lua.

If you were to choose JavaScript for your backend, you could use Node.js, Express, and some other external packages like request and xml2js to make this happen.

// server.js on web server

// Get external packages 
const express = require("express");
const app = express();

const xmlParser = new require("xml2js").Parser({ignoreAttrs:true});
const request = require("request");

// Listen for requests 
app.get("/", function(request, response) {
    var playerid = request.query.playerid;
    var groupid = request.query.groupid;
    // Sends a request to the Roblox API
    request("https://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid="+playerid+"&groupid="+groupid, function(err,res,body) {
        parser.parseString(body,function(err,result) {
            response.send(body);
        });
    });
});

// Note: This is missing app.listen(), but if you were to include it here, this code should work.

You could host this on a web server (Glitch, repl.it, a server of your own, etc.) and use HttpService to see if a player is in a group or not.

-- Server script on Roblox

local HttpService = game:GetService("HttpService")

local WebServer = "https://playerisingroup.glitch.me" -- For an example, the domain is this. Replace it with your domain if you wish
local GroupId = 0
local PlayerId = 0

if HttpService:GetAsync(WebServer.."?playerid="..PlayerId.."&groupid="..GroupId) == "true" then
    -- Player is in group
else
    -- Player is not in group
end

I made a JavaScript app in Glitch for this question, but you can use the domain or code for your own script if you want to.

Ad

Answer this question