Automatically give player uniform depends on their rank in group

  1. What do you want to achieve? Keep it simple and clear!
    This is already second topic about this problem, i need to give player uniform depends on their rank. This what i mean:
    Rank in Group | Uniform
    1 | E1
    2 | E2
    3 | E3
    4 | E4
    5 | E5
    6 | E6
    7 | E7
    And etc

  2. What is the issue? Include screenshots / videos if possible! Idk how to make auto sort system of uniform, so i need to get rank in group and use it as getting uniform

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to use for loop, but did some mistakes with it

My code:

local GroupID = 11357936
local Script = script.Parent
function Click(player)
	
	local pName = player.Name
	local pPlayer = game.Workspace:FindFirstChild(pName)
	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) 
local GroupID = 11357936
local Script = script.Parent
function Click(player)
	
	local pName = player.Name
	local pPlayer = game.Workspace:FindFirstChild(pName)
	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) 

There are a few solutions to this. The best one would be using a table and setting the value for each rank, but I will show a bit different and easier method (let me know if you want to know the table method and ill explain that too)

So first you have to make the uniforms and separate them by rank, by putting them in a folder or group. So let’s say now you have 3 folders (or as many as you want), and all of them have the pants, shirt, accessories and everything else you want to put on the player. Make sure that the folders are named correctly, so the uniform for the rank “1” is named “E1” (or anything that ends with “1”). Now group these folders together, name the group “Uniforms” and put it in the ReplicatedStorage.

function something(player)

	local PlayerRank = player:GetRankInGroup(GroupID)
	local PlayerCharacter = player.Character -- an easier way to get the character
	local uniforms = game.ReplicatedStorage.Uniforms

	for i, c in pairs(PlayerCharacter:GetChildren()) do
		if c:IsA("Pants") or c:IsA("Shirt") then
			c:Destroy()
		end
	end

	local rankUniform = uniforms:FindFirstChild("E"..PlayerRank) -- gets the folder
	
	if rankUniform then
		for i, u in pairs(rankUniform:GetChildren()) do
			local clone = u:Clone()
			clone.Parent = PlayerCharacter -- clones everything inside the folder into the players character
		end
	end

end

Hope it works

1 Like

Although this gonna work But, i have an unregular ranks like E8A & E8B, E9A & E9B, and this ain’t gonna work for them

Ok nvm i can just use them as E12 or smth like that

You dont even need the E, you can just assign them by plain number and then it wont matter that there’s an A or B

1 Like

Ok so only reason, i have 255 rank in group(and other some roles have 251+ rank in group), and i have last is rank 21, but last uniform is for rank21 and i don’t get uniform

Are there any errors in the output? Also, check again if the folder is named correctly and is in the right place because if it isn’t, there won’t be any errors and just won’t work

1 Like

Ok nvm nothing works, i remade a code a bit(bcz need it)

local GroupID = 11357936
local Script = script.Parent
function something(player)

	local PlayerRank = player:GetRankInGroup(GroupID)
	local PlayerCharacter = player.Character -- an easier way to get the character
	local uniforms = game.ReplicatedStorage.Uniform.BlueAlphas

	for i, c in pairs(PlayerCharacter:GetChildren()) do
		if c:IsA("Pants") or c:IsA("Shirt") then
			c:Destroy()
		end
	end
	
	local rankUniform = uniforms:FindFirstChild(PlayerRank) -- gets the folder
	
	if PlayerRank > 251 then
		local Shirt = uniforms["21"].Shirt
		local Pants = uniforms["21"].Pants
		local ShirtClone = Shirt:Clone()
		ShirtClone.Parent = PlayerCharacter
		
		local PantsClone = Pants:Clone()
		PantsClone.Parent = PlayerCharacter
	end
	
	if rankUniform then
		for i, u in pairs(rankUniform:GetChildren()) do
			local clone = u:Clone()
			clone.Parent = PlayerCharacter -- clones everything inside the folder into the players character
		end
	end

end

Also here is how uniform looks

Edit: I don’t see any errors in output

Wait, i don’t call this function when i click text button, this is problem. I just declare function, but how do i add a MouseButton1Click function here tho?

Ok nvm i using remote Events right now to optimize scripts(use one server script and a lot of local script), but now i get error when i’m sending name of uniform to server script
image
Server Script:

local GroupID = 11357936
local UniformEvent = game:GetService("Workspace").RemoteEvents.UniformChange
UniformEvent.OnServerEvent:Connect(function(player, uniformType)

	local PlayerRank = player:GetRankInGroup(GroupID)
	local PlayerCharacter = player.Character -- an easier way to get the character
	local uniforms = game.ReplicatedStorage.Uniform..uniformType

	for i, c in pairs(PlayerCharacter:GetChildren()) do
		if c:IsA("Pants") or c:IsA("Shirt") then
			c:Destroy()
		end
	end
	
	local rankUniform = uniforms:FindFirstChild(PlayerRank) -- gets the folder
	
	if PlayerRank > 251 then
		local Shirt = uniforms["21"].Shirt
		local Pants = uniforms["21"].Pants
		local ShirtClone = Shirt:Clone()
		ShirtClone.Parent = PlayerCharacter
		
		local PantsClone = Pants:Clone()
		PantsClone.Parent = PlayerCharacter
	end
	
	if rankUniform then
		for i, u in pairs(rankUniform:GetChildren()) do
			local clone = u:Clone()
			clone.Parent = PlayerCharacter -- clones everything inside the folder into the players character
	end	
end
end)

Local Script:

local Button = script.Parent
local UniformEvent = game:GetService("Workspace").RemoteEvents.UniformChange
local player = game:GetService("Players").LocalPlayer
Button.MouseButton1Click:Connect(function()
	UniformEvent:FireServer(player, "BlueAlphas")
end)

If you look on line 7 you accidentally put .Uniform..uniformType.

this is not accident uniformType is string what i send from remote event

Wait nevermind, you are meant to do game.ReplicatedStorage.Uniform[uniformType] instead of game.ReplicatedStorage.Uniform..uniformType.


Same result

On the client, you are not supposed to send the player, since the first argument of OnServerEvent is always the player who fired it., try removing player, .

Finally it works, thanks you for help, @WoTrox thanks for script remake. Idk who mark as solution

1 Like