Problem With Uniform Giver

What I had been working on is called the Uniform giver. You press a button on the side of your screen, you get options for LR uniform, MR uniform, and the HR one opens another gui part that gives you Male or Female uniform options. Here is what i have - and both are 2 diff scripts

local par = script.Parent
local remote = par.RemoteEvent

local ShirtId1 = 14548206090
local PantsId1 = 14555518246

local ShirtId2 = 18249142984
local PantsId2 = 18249137510

local MIN_RANK1 = 10
local MIN_RANK2 = 119
local GROUP_ID = 5901406

remote.OnServerEvent:Connect(function(player, info)
	local success, roles = pcall(function()
		return player:GetRolesInGroup(GROUP_ID)
	end)

	if not success then
		warn("Failed to get roles for player:", player.Name)
		return
	end

	if info == "Button1" then
		if player:GetRankInGroup(GROUP_ID) >= MIN_RANK1 then
			local character = player.Character
			if character then
				local shirt = character:FindFirstChild("Shirt")
				local pants = character:FindFirstChild("Pants")

				if shirt then
					shirt:Destroy()
				end
				if pants then
					pants:Destroy()
				end

				local newShirt = Instance.new("Shirt")
				newShirt.ShirtTemplate = "rbxassetid://" .. ShirtId1
				newShirt.Parent = character

				local newPants = Instance.new("Pants")
				newPants.PantsTemplate = "rbxassetid://" .. PantsId1
				newPants.Parent = character
			end
		end
	elseif info == "Button2" then
		if player:GetRankInGroup(GROUP_ID) >= MIN_RANK2 then
			local character = player.Character
			if character then
				local shirt = character:FindFirstChild("Shirt")
				local pants = character:FindFirstChild("Pants")

				if shirt then
					shirt:Destroy()
				end
				if pants then
					pants:Destroy()
				end

				local newShirt = Instance.new("Shirt")
				newShirt.ShirtTemplate = "rbxassetid://" .. ShirtId2
				newShirt.Parent = character

				local newPants = Instance.new("Pants")
				newPants.PantsTemplate = "rbxassetid://" .. PantsId2
				newPants.Parent = character
			end
		end
	end
end)
local par = script.Parent
local remote = par.RemoteEvent

local ShirtIdM = 18240050175
local PantsIdM = 18240063068

local ShirtIdF = 18240497439
local PantsIdF = 18240060981

local MIN_RANK_HR = 125
local GROUP_ID = 5901406

remote.OnServerEvent:Connect(function(player, info)
	local success, roles = pcall(function()
		return player:GetRolesInGroup(GROUP_ID)
	end)

	if not success then
		warn("Failed to get roles for player:", player.Name)
		return
	end

	print(player.Name, "roles:", roles)
	print(player.Name, "rank:", player:GetRankInGroup(GROUP_ID))

	local function applyUniform(shirtId, pantsId)
		local character = player.Character
		if character then
			local shirt = character:FindFirstChild("Shirt")
			local pants = character:FindFirstChild("Pants")

			if shirt then
				shirt:Destroy()
			end
			if pants then
				pants:Destroy()
			end

			local newShirt = Instance.new("Shirt")
			newShirt.ShirtTemplate = "rbxassetid://" .. shirtId
			newShirt.Parent = character

			local newPants = Instance.new("Pants")
			newPants.PantsTemplate = "rbxassetid://" .. pantsId
			newPants.Parent = character
		end
	end

	if info == "ButtonM" and player:GetRankInGroup(GROUP_ID) >= MIN_RANK_HR then
		applyUniform(ShirtIdM, PantsIdM)
	elseif info == "ButtonF" and player:GetRankInGroup(GROUP_ID) >= MIN_RANK_HR then
		applyUniform(ShirtIdF, PantsIdF)
	end
end)

and when testing the output said this:
Failed to get roles for player: jjustnoraa - Server - Script:19

What is happening? Why wont it work?

1 Like

The pcall failed and wasn’t able to GetRolesInGroup(GROUP_ID)

1 Like

How can I fix? Where is the problem?

Remove the pcall and just call it as normal to see why it is failing …
Definitely focus on that error for now.

or change the call to show it …

local success, err = pcall(function()
	--
end)

if not success then
	print(err)
end
1 Like

Remove the line “local success, roles = pcall(function()”, and the “end)” line which is 2 lines below the line “local success, roles = pcall(function()”. Then, post the error that occurs when the code is run without those two lines of code

1 Like

it shows the red squiggly under the word “roles” for other lines when i do that

You need to create a variable that is equal to nil with the name of “roles” for that mate. Its because there is no pointer

1 Like

how can i do that? i am very lost…

change that bit to

remote.OnServerEvent:Connect(function(player, info)
	local roles =  player:GetRolesInGroup(GROUP_ID)

ignore where i said nil variable that was a different scenario.
post the error/output you get when you run this

1 Like
15:49:01.102  GetRolesInGroup is not a valid member of Player "Players.jjustnoraa"  -  Server - Script:27
  15:49:01.103  Stack Begin  -  Studio
  15:49:01.103  Script 'Players.jjustnoraa.PlayerGui.UniformSelectionGui.UniformSelectionMenu2.Script', Line 27  -  Studio - Script:27
  15:49:01.103  Stack End  -  Studio

line 27 is

local roles =  player:GetRolesInGroup(GROUP_ID)

Found the issue mate, its not GetRolesInGroup, it is GetRoleInGroup. You had a typo.

1 Like

Thanks! I worked but one problem, once i chose a uniform, let say i pressed male uniform by accident and i need to switch it, it wont work, it just puts my role in group like im ceo so it puts that in output but doesnt change my uniform… why?

16:00:34.226  jjustnoraa roles: 22 | Chief Executive Officer  -  Server - Script:34
 16:00:34.226  jjustnoraa rank: 255  -  Server - Script:35

is there something else that was needed for change?

Must be something to do with the applyUniform function, lemme have a look at it

1 Like

I’m not sure I dont see anything wrong with the code as well as the logic part at the bottom where the function is called. Print some random stuff out throughout the script and debug it, and tell me where it just doesnt print.

Another thing I have realised is, with the first script sample you provided the info values are “Button1” and “Button2”, and for the second its “ButtonM” and “ButtonF”. Is this intentional?

1 Like

the 1st script is for LR and MR and the 2nd is for HR but female and male…
im currently working on the HR script with these corrections,

local par = script.Parent
local remote = script.Parent.RemoteEvent

local ButtonM = par.WearMaleButton
local ButtonF = par.WearFemaleUniform

ButtonM.MouseButton1Click:Connect(function()
	remote:FireServer("ButtonM")
	par.Visible = false
end)

ButtonF.MouseButton1Click:Connect(function()
	remote:FireServer("ButtonF")
	par.Visible = false
end)

Do you have discord by any chance? Its easier to communicate there

Forgot to ask, why do you have this as 2 different scripts when you can just combine them into one?

1 Like

here hope this explains:
image
i was afraid it wouldnt work if the remote event was under only the other selection menu.

and yes i do have, its jjustnoraa

Aight I sent a request I’ve got the happy meal pfp

1 Like