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
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
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
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
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
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
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)
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, .