Need help with group only chat commands

Hey! I recently made a chat command, that displays (makes visible) an overhead icon. I also want to implement a group check, whether the player sending the command is in whitelisted groups or not. Meaning if a player is not in any of those groups, it won’t do anything at all.

However, the script still runs and icon is set to visible, even when im not in any of the entered groups.

Code:

game.Players.PlayerAdded:Connect(function(Player)
	if Player:IsInGroup(13947653) or (13944389) or (13944487) or (13947692) or (11447389) == true then
		Player.Chatted:Connect(function(Message)
			local Words = string.split(Message, " ")

			if Words[1] == "!clear" then
				local NameOfPlayerToClear = Words[2]
				local PlayerToClear = NameOfPlayerToClear:lower()
				for _, player in ipairs(game:GetService("Players"):GetPlayers()) do 
					if player.Name:lower():sub(1, #PlayerToClear) == PlayerToClear then
						player.Character.Head.GUI.Icons.ClearedIcon.Visible = true
					end
				end
			end
		end)
	else
		print("You're not in a divisional group!")
	end
	
end)
1 Like

The second line is what is causing this, you need to call :IsInGroup() for every individual group id
Eg: :IsInGroup(1) or :IsInGroup(2) also, no need for the == true

2 Likes

Thanks, works perfectly now, as I want it to work!

2 Likes

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