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

Why is Player:IsInGroup returning nil??

Asked by 5 years ago

So I wanted to make like a Gui that would give stuff if you are in a particular group. Since I am using local Script for Gui's, I decided to use Remote Function to get if a player is in group or not since that feature only works in server script.

The thing is that my conditional statement does not seem to be working. The Remote Function instead of returning true or false, it seems to return nil.

Have I somehow messed up writing the parameter?

-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFunctions = ReplicatedStorage:WaitForChild("RemoteFunctions")
local GetPlayerGroupInfo = RemoteFunctions:WaitForChild("GetPlayerGroupInfo")

local function GetPlayerGroupData (player)
    return player:IsInGroup(0000000) -- I just wrote it like that :P
end

GetPlayerGroupInfo.OnServerInvoke = GetPlayerGroupData

-- Client Script
GetPlayerGroupInfo:InvokeServer()
local GetPlayerValue = GetPlayerGroupInfo

if GetPlayerValue == true then
    print("Local Player in Group")
elseif GetPlayerValue == false then 
    print("Local Player not in Group")
else
    print("Not Working")
end

It seems to be printing the else statement; Not Working. What am I doing wrong here????

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

GetPlayerValue is being set to the remote function itself, rather than what it is returning. So, it is an object rather than being true or false. If you want to invoke the remote function, you should do:

local GetPlayerValue = GetPlayerGroupInfo:InvokeServer()

However, IsInGroup can be called by the client as well as the server, and it is even often better to call it from the client due to up-to-date information. As a result, you shouldn't need the server script at all, and should just be able to do it in the LocalScript. However, if you are planning on giving the player group exclusive items, this will need to be done with a server script.

0
Oh Interesting. I did check if I was setting the getplayervalue to an object but my knowledge is pretty limited and I failed to pick that up. Thanks a lot! LightYagamiTheKira 116 — 5y
Ad

Answer this question