Error when checking if player is in a group ):

Hello developers,

I need some help. I want to check if a player is a Star Creator, be checking if they’re inside of the Star Creator group.

My error is…

attempt to call missing method 'IsInGroup' of string

Now I have check the Roblox docs and they don’t help

The Roblox Docs Code for "IsInGroup"
local Players = game:GetService("Players")

local function onPlayerAdded(player)
	if player:IsInGroup(7) then
		print("Player is in the Roblox Fan club!")



Now this is a Server Script, and the function runs when the client fires a RemoteEvent

-- Sent From Client
SearchEvent.OnServerEvent:Connect(function(Player, SearchedUser)
	local Data
	local Success, Error = pcall(function()
		Data = PlayerData:GetAsync(Players:GetUserIdFromNameAsync(SearchedUser))
	local UserId = Players:GetUserIdFromNameAsync(SearchedUser)
	local SearchedName = Players:GetNameFromUserIdAsync(UserId)
	if SearchedName:IsInGroup(4199740) then -- LINE ERROR! ⚠️
		print("Is a star creator")
	if Success and Data then
		SearchEvent:FireClient(Player, UserId, true)
		SearchEvent:FireClient(Player, UserId, false)

You have Player as an argument in your OnServerEvent function, can’t you just use that?

if Player:IsInGroup(4199740) then

No, not really. I want users to be able to search for a user, so I have in my function SearchEvent.OnServerEvent:Connect(function(Player,SearchedUser )

And for some random reason it doesn’t work. You may notice that instead of SearchedUser it’s SearchedName. That’s because I was thinking that, maybe changing from Username → UserId → Username it might work. I think it worked before, but clearly it doesn’t work here.

Maybe try Players :GetPlayerByUserId (PlayerId) instead of username

Looks like I get nil. I think that’s because the player I’m searching for isn’t in the server.

I guess I should of also said, that I want to search for the player even when their not in the game. Oops, sorry.

Player:IsInGroup should work even if the player isn’t in the server
Let me check somthing

I think it’s impossible to get a player object that is outside the game

You’re attempting to use the IsInGroup() method on a string value (SearchedName)

You can try using the GetUserIdFromNameAsync() method and then use GroupService to create your own equivalent of IsInGroup.

Players | Roblox Creator Documentation
GroupService | Roblox Creator Documentation

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.