PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GroupService

Show deprecated

GroupService

Show deprecated

GroupService is a service that allows developers to fetch information about a Roblox group from within a game.

Basic information on the group, including it’s name, description, owner, roles and emblem can be fetched using GroupService/GetGroupInfoAsync. Lists of a group’s allies and enemies can be fetched using GroupService/GetAlliesAsync and GroupService/GetEnemiesAsync.

GroupService can also be used to fetch a list of group’s a player is a member of, using GroupService/GetGroupsAsync. Note, developers wishing to verify if a player is in a group should use the Player Player/IsInGroup function rather than GroupService/GetGroupsAsync.

The service has a number of useful applications, such as detecting if a player is an ally or enemy upon joining the game.

Properties

Inherited from Instance: Show Hide

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to

int

DataCost

[ReadOnly] [NotReplicated] [Deprecated]

The cost of saving the instance using data persistence.

string

Name

A non-unique identifier of the Instance

Instance

Parent

Determines the hierarchical parent of the Instance

bool

RobloxLocked

If true, the Instance and its descendants cannot be indexed or edited by a Script or LocalScript and will throw an error if it is attempted

bool

archivable

[Hidden] [NotReplicated] [Deprecated]
string

className

[ReadOnly] [NotReplicated] [Deprecated]

Functions

Instance

GetAlliesAsync ( int64 groupId )

[Yields]

Returns a StandardPages object including information on all of the specified group’s allies.

Instance

GetEnemiesAsync ( int64 groupId )

[Yields]

Returns a StandardPages object including information on all of the specified group’s enemies.

Variant

GetGroupInfoAsync ( int64 groupId )

[Yields]

Returns a table containing information about the given group.

Array

GetGroupsAsync ( int64 userId )

[Yields]

Returns a list of tables containing information on all of the groups a given player is a member of

Inherited from Instance: Show Hide

void

ClearAllChildren ( )

This function destroys all of an Instance's children.

Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where Archivable = true.

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

Variant

GetAttribute ( string attribute )

RBXScriptSignal

GetAttributeChangedSignal ( string attribute )

Dictionary

GetAttributes ( )

Objects

GetChildren ( )

Returns an array containing all of the Instance's children.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

string

GetFullName ( )

Returns a string describing the Instance's ancestry.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

bool

IsA ( string className )

[CustomLuaState]

Returns true if an Instance's class matches or inherits from a given class

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

void

Remove ( )

[Deprecated]

Sets the object’s Parent to nil, and does the same for all its descendants.

void

SetAttribute ( string attribute , Variant value )

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Objects

children ( )

[Deprecated]

Returns an array of the object’s children.

Instance

clone ( )

[Deprecated]
void

destroy ( )

[Deprecated]
Instance

findFirstChild ( string name , bool recursive )

[Deprecated]
Objects

getChildren ( )

[Deprecated]
bool

isA ( string className )

[Deprecated] [CustomLuaState]
bool

isDescendantOf ( Instance ancestor )

[Deprecated]
void

remove ( )

[Deprecated]

Events

Inherited from Instance: Show Hide

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

AttributeChanged ( string attribute )

RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

childAdded ( Instance child )

[Deprecated]

Code Samples


Group Ally/Enemy Checker

This code sample demonstrates how GroupService and Player/IsInGroup can be used to determine whether a player is a member of a group, or any of its allies or enemies.

Note as GroupService/GetAlliesAsync and GroupService/GetEnemiesAsync use StandardPages objects a utility function is used to convert them to allies.

    local GroupService = game:GetService("GroupService")
    local Players = game:GetService("Players")
    
    -- define group id here
    local GROUP_ID = 271454
    
    -- utility function for dealing with pages
    local function pagesToArray(pages)
    	local array = {}
    	while true do
    		for k, v in pairs(pages:GetCurrentPage()) do 
    			table.insert(array, v)
    		end
    		if pages.isFinished then
    			break
    		end
    		pages:AdvanceToNextPageAsync()
    	end
    	return array
    end
    
    -- get lists of allies and enemies
    local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
    local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
    
    -- convert to array
    local allies = pagesToArray(alliesPages)
    local enemies = pagesToArray(enemiesPages)
    
    local function playerAdded(player)
    	-- check to see if the player is in the group
    	if player:IsInGroup(GROUP_ID) then
    		print(player.Name.." is a member!")
    	else 
    		local isAlly, isEnemy = false, false 
    
    		-- check to see if the player is in any ally groups
    		for _, groupInfo in pairs(allies) do
    			local groupId = groupInfo.Id
    			if groupInfo then
    				if player:IsInGroup(groupId) then 
    					isAlly = true
    					break
    				end
    			end
    		end
    
    		-- check to see if the player is in any enemy groups
    		for _, groupInfo in pairs(enemies) do
    			local groupId = groupInfo.Id
    			if groupInfo then
    				if player:IsInGroup(groupId) then 
    					isEnemy = true
    					break
    				end
    			end
    		end
    
    		if isAlly and not isEnemy then 
    			print(player.Name.." is an ally!")
    		elseif isEnemy and not isAlly then
    			print(player.Name.." is an enemy!")
    		elseif isEnemy and isAlly then
    			print(player.Name.." is both an ally and an enemy!")
    		else 
    			print(player.Name.." is neither an ally or an enemy!")
    		end
    	end
    end
    
    -- listen for new players being added
    Players.PlayerAdded:Connect(playerAdded)
    
    -- handle players already in game
    for _, player in pairs(Players:GetPlayers()) do
    	playerAdded(player)
    end