Attempt to index nil with "IsInGroup"

Hello,
I want to be able to give people uniforms based on their rank in their division when clicking a button called “Spawn”, but I’m running into the following problem. The Rank value is included as NumberValue.
Besides that, I also have a simple module with the divisions.

The script attempts to index nil with “IsInGroup”

I’ve changed to code to several different things, but to no avail.

Advice on how to fix this is very much appreciated!

Code:

--Variables
local MorphsDir = game.ReplicatedStorage.Morphs
local Libs = game.ReplicatedStorage.Libs
local Divisions = require(Libs.Divisions)
local Player = game.Players.LocalPlayer

	for i = 1,#Divisions do
		if Player:IsInGroup(Divisions[i].GroupId) or Divisions[i].GroupId == 0 then
--code
			Button.MouseButton1Click:Connect(function ()
				for i,v2 in pairs(UniformsFrame:GetChildren()) do
					if v2.ClassName == "TextButton" then
						v2:Destroy()
					end
				end
				for i,v3 in pairs(MorphsDir[Divisions[i].Name]:GetChildren()) do
					
					local Allowed = true

					if v3:FindFirstChild("Rank") then
						if Player:GetRankInGroup(Divisions[i].GroupId) == Player:GetRankInGroup(Divisions[i].GroupId) then
							Allowed = true
						else
							Allowed = false
						end
					end
					if Allowed then
-- end of used code

Module:

local Divisions = {
	{
		Name = "Name";
		GroupId = #Number;
	};
	MainGroup = #Number;
}

return Divisions

--GroupId and MainGroupId not included in the example above.

Is this a server script or a local script?

Because LocalPlayer is only used on a LocalScript, you should not use LocalPlayer for this case, nor LocalScript, since you want the visual to be displayed over the server.

From the server script, you want to listen for the Players.PlayerAdded event(the first parameter is player that joined) and the execute that entire code for them.

Also note that the Player instance passed with the signal is not a descendant of players when it first fired, so it is best practice to make sure you can use the IsInGroup and others on it, you can listen for AncestryChanged IIRC.

IsInGroup returns a bool and your’re trying to compare it to something else, are you trying to get a players rank instead?

Yes, I am trying to get a rank instead.

Local script which is situated inside of a GUI.

Sorry for the delayed reply. Checking if a player is in a group/checking their rank/role in a group requires it to be done on the server.