Customisation Requirements not working

So basically, I’ve got a character customization function that should return if the player can wear that piece of clothing (whether they’re on in the specific group, team or own an asset)

For some reason, this doesn’t work as expected. Some people end up unlocking EVERYTHING when the requirements in the module obviously shouldn’t allow it. I’ve attempted to debug this for weeks and just ended up giving up. I did try adding less things to the module (2 items) and it worked fine, it’s as if the function got overloaded and decided to return true (obviously this isn’t what is happening but its just really confusing) I think it’s the way the function is checking the groups but I’m not sure anymore

Module:
(Rough selection of it so you can understand how I’m writing the requirements, full: https://pastebin.com/3JD1DG4p)

return {
	Accessories = {
		['Standard Issue Webbing'] = {
			teamRequirements = {'Armed Forces', 'Basic Training'},
			gamepassRequirements = {},
			groupRequirements = {3877279},
				
			accessories = {Webbing.Backpack}
		},
	},
	Uniforms = {
		['Grenadier Guard Formals'] = {
			teamRequirements = {'Grenadier Guards'},
			gamepassRequirements = {},
			groupRequirements = {4428388},
				
			shirts = {GrenUniform.CGGFormals},
			pants = {GrenUniform.CGGFormalUniversal},
		},
		['The Founder'] = {
			teamRequirements = {'The Founder'},
			gamepassRequirements = {},
			groupRequirements = {{Group = 3876907, Rank = {'-20'} }},
				
			shirts = {StaffUniform.FoundersShirt},
			pants = {StaffUniform.FoundersPants},
		},
		
	},
	Covers = {
		['Parachute Battalion Beret'] = {
			teamRequirements = {'Parachute Battalion'},
			gamepassRequirements = {},
			groupRequirements = {4259147},
				
			covers = {HatFolder['Parachute Battalion Beret']},
		},
		['Sovereigns Hat'] = {
			teamRequirements = {'Community Manager'},
			gamepassRequirements = {},
			groupRequirements = {{Group = 3876907, Rank = {'-20'} }},
				
			covers = {UniformFolder['Founders Hat']},
		},
		
	}	
}

Check Function

module.PlayerHasAccessToUniform = function(Player, args)	
	local requirements = args.requirements
	local requestedToCheck = args.requestingToCheck
	
      -- Right so here, requestedToCheck is just a string such as `gamepassRequirement`

	if requestedToCheck then
		for _, value in next, requirements do
			if requestedToCheck == 'gamepassRequirements' then
				if marketPlaceService:UserOwnsGamePassAsync(Player.UserId, value) then
					return true
				end
			elseif requestedToCheck == 'teamRequirements' then
				
				if value == 'All' then
					return true
				elseif Player.Team.Name == value then
					return true
				else
					return false
				end
			elseif requestedToCheck == 'groupRequirements' then
				local function checkIfPlayerInGroup(group, rank, checkMoreThanOrEqual)
					rank = tonumber(rank)
					if Player:IsInGroup(group) then
						-- 
						if rank then
							if checkMoreThanOrEqual then
								if Player:GetRankInGroup(group) >= rank then
									return true
								end
							else
								if Player:GetRankInGroup(group) == rank then
									return true
								end
							end
						else
							return true
						end
					else
						return false
					end
				end
				if type(value) == 'table' then
					--print('Table value')
					local group = value.Group
					local rank = value.Rank or value.Ranks
					
					if not rank then
						return false
					end
										
					for _, id in next, rank do
						local length  = string.len(id)
						if string.sub(id, string.len(1), string.len(1)) == '-' then
							-- our value wants us to do rank >=
							local newId = string.sub(id, 2, string.len(id))
							--print('Checking2: '..group .. id)
							local isIn = checkIfPlayerInGroup(group, id, true)
							if isIn then
								return true
							end
						else
							--print('Checking2: '..group .. id)
							local isIn = checkIfPlayerInGroup(group, id, nil)
							if isIn then
								return true
							end
						end
					end
				else
					--print('Checking3: '..value )
					return checkIfPlayerInGroup(value, nil, nil)
				end
			end
		end
	end
end

I think my main issue is coming from the groupRequirements check, my apologies if the code is a bit much I just can’t describe it any easier. I’ll happily answer any questions about the code if needed.

Thanks

1 Like

Hi SovereignFrost!

I saw your issue right away, it’s a simple mistake.

Since you are returning values it just returns a single value, true or false, not everything. I would use a table and return that. the "for _, value in pair- or next? never seen that before but moving on, the loop is canceled as soon as one item is deemed true.

PS. it seems you are anticipating them to come all at different times so since the first one is all you probably gave them all the items. I would change that too.

Hope this helped, -HiddenKaiser

I probably should of more clear, sorry. The function is checking an individual item.

local DataGroup = uniData[args.DataGroup]
local ItemName = DataGroup[args.ItemName]

local tableOfRequirements = {gamepassRequirements = ItemName.gamepassRequirements, teamRequirements = ItemName.teamRequirements, groupRequirements = ItemName.groupRequirements}

for name, req in next, tableOfRequirements do
	if req then
		if module.PlayerHasAccessToUniform(Player, {requirements = req, requestingToCheck = name}) then
			spawn(function()
				module.AlterAppearance(Player, {
					datagroup = args.DataGroup,
					name = args.ItemName
								
				})
			end)
			return true
		end
	end
end
1 Like

Is the table linked in your pastebin in another module and args is just local args = require(thatOneModuleWithTheTable)? I doesn’t look like that is the case so its very strange.

It is very strange that when you removed a few args it worked. Only thing i could think of would be misplacement of commas but that seems to be different. I have never encountered this issue but maybe you should try doing something like “local module = {” for the table instead of returning it as “return {”. When you create a module script it comes out like that so that might be a case. This happens sometimes with TextBoxes such as local text = int .."Lol#4 guys" instead of (int .."Lol#4 guys")

Keep me updated, -HiddenKaiser

The module is in ReplicatedStorage, the server requires it. I just haven’t included all of the code for simplicity sake and not overloading code.

Comas are perfect to what I’ve looked through, really strange. I’m taking that it’s an issue with the function

Very strange. I am very sorry I was unable to help you. I’m sure another developer can help you with this strange mystery. If worse comes to worse you might just have to ditch the table but at this point I wouldn’t even take advice from me.

So now, I pass the mic to any other developers who can help you as I cannot.

Inside of your loop, you don’t check if the index is equivalent to what you’re trying to check. Is this intentional? I don’t see a reason you wouldn’t check the index.

For example,
if requestedToCheck == 'gamepassRequirements' then
to
if requestedToCheck == index then

1 Like

The loop is outdated, I should of just done requirements[requestedToCheck]
The code calling the function indicates the requirement that it needs to check.

I’ve gone and well… quite embarrassing actually.
In my code I use make a newId variable to remove the - from the string rank which is just an indicator to use a >= sign, I however was checking the old id. I believe this is going to fix the issue as it was checking for >= -6 instead of >= 6.

3 Likes