Automatically sort uniform depends on player group rank

  1. What do you want to achieve? Keep it simple and clear!
    So basically, i need to automatically sort uniform by player group rank, like player rank in group = 1 then uniform will be = E1.

  2. What is the issue? Include screenshots / videos if possible!
    Idk how to do that. Also i get this error
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I can make a long script, but it’s not optimized and it will lag a lot.

My script:

local GroupID = 11357936
local Script = script.Parent
function Click(mouse)
	
	local pName = script.Parent.Parent.Parent.Parent.Parent.Name
	local pPlayer = game.Workspace:findFirstChild(pName)
	local Player = game.Players:GetPlayerFromCharacter(pPlayer)
	local PlayerRank = Player:GetRankInGroup(GroupID)
	for j,k in pairs(pPlayer:GetChildren()) do
		if k:IsA("Pants") or k:IsA("Shirt") then
			k:destroy()
		end
	end
	for i, Rank in ipairs(Script:GetChildren()) do
		Rank:clone().Parent = pPlayer
		Rank:clone().Parent = pPlayer
	end
end

script.Parent.MouseButton1Click:connect(Click) 

Player is probably nil Thats why its not working.

No bcz i took that script from working system and made it same, player is not nil.

you have an error in your code
FindFirstChild() not findFirstChild()

This looks a bit roundabout, considering MouseButton1Click sends the player (not the character) who clicked said button

function Clicked(player)
  print(player.Name .. " clicked me")
end

… I already stated what all this script works without adding my part of code with rank

Is this a TextButton or is it a ClickDetector?

TextButton (30 letterssssssssss)