Error with IsInGroup()

Hello everyone!

I am currently working on an elevator game, and I want to make group rewards. However, it shows this error when I am using the IsInGroup() function for line number 5:


Here is a sample of my code as well:

local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336

script.Parent.Touched:Connect(function(hit)
	if not game.Players:FindFirstChild(hit.Parent.Name):IsInGroup(groupid) then
		if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
			local plr = game.Players[hit.Parent.Name]
			if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
				GUI:Clone().Parent = plr.PlayerGui
			end
		end
	elseif game.Players:GetPlayerFromCharacter(hit.Parent):IsInGroup(groupid) then
		script.Parent.CanCollide = false
		script.Parent.Transparency = 0.9
		wait(3)
		script.Parent.CanCollide = true
		script.Parent.Transparency = 0.7
	end
end)

So when the player has touched the part, the script will check if the player is in the group or not. If the player is not in the group, it will pop up a GUI. If the player is in the group, it will make it so that way the door’s CanCollide property is false.

Again, I am not sure how to fix this, since I have tried everything to fix it and it is still not working. If anyone can find any solution to this, please inform me of this. Any and all fixes are appreciated.

Thank you!

You can print the hit.Parent. I assume it’s not getting the player.

1 Like
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336

script.Parent.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

	if Player and not Player:IsInGroup(groupid) then
		 if Player.PlayerGui:FindFirstChild(GUI.Name) then
		    GUI:Clone().Parent = Player.PlayerGui
		end
		
	elseif Player and Player:IsInGroup(groupid) then
		script.Parent.CanCollide = false
		script.Parent.Transparency = 0.9
		task.wait(3)
		script.Parent.CanCollide = true
		script.Parent.Transparency = 0.7
	end
end)
1 Like

hit.Parent should be the character whenever the player touches the part, then from there I get the player using the game.Players:GetPlayerFromCharacter line. I have printed out hit.Parent, and it prints out my username which is the character.

1 Like
local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336

script.Parent.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

	if Player then
	    if not Player:IsInGroup(groupid) then
	        if not Player.PlayerGui:FindFirstChild(GUI.Name) then
		        GUI:Clone().Parent = Player.PlayerGui
		    end
		else
	        script.Parent.CanCollide = false
		    script.Parent.Transparency = 0.9
		    task.wait(3)
		    script.Parent.CanCollide = true
    		script.Parent.Transparency = 0.7
		end
	end

end)

This looks nicer.

EDIT:
Made some changes.

1 Like

I’m testing it right now with my alt acc.

It doesn’t show the error anymore, but it also doesn’t show the GUI.

I already made the changes, use that.

1 Like

I have, it still doesn’t work. I am currently trying out more solutions with your code.

Same error even with his code?

No, the error isn’t showing up anymore. However, it is still not showing the GUI.

Hi!

Please go ahead and put a print before “If Player then”

print(Player)
if Player then

Try this for debugging, then send a screen shot of your output


local GUI = script.Parent.NotInGroupGUI
local groupid = 14619336

script.Parent.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

	if Player then
        print("Player exists!")
	    if not Player:IsInGroup(groupid) then
            print("Player is not in group")
	        if not Player.PlayerGui:FindFirstChild(GUI.Name) then
                print("GUI not being shown")
		        GUI:Clone().Parent = Player.PlayerGui
		    end
		else
            print("Is in group")
	        script.Parent.CanCollide = false
		    script.Parent.Transparency = 0.9
		    task.wait(3)
		    script.Parent.CanCollide = true
    		script.Parent.Transparency = 0.7
		end
	end

end)

1 Like

This prints out my username from the local Player = game.Players:GetPlayerFromCharacter(hit.Parent).

Try the debugging script I posted above and let us know what gets printed

1 Like

I am aware that it would do so, if the Player is present. If the Player wasn’t present, then it would print nil. :slight_smile:

1 Like

player isn't in group
I used my alt account to test this.

So this is saying that the player has the GUI in the player gui already

1 Like

Yes, but for some weird reason, it isn’t showing up like it is supposed to do.

Have you checked if the GUI is inside the player’s PlayerGUI after hitting the part?