-
What do you want to achieve?
I want the player to know how rare their unlocked texture/skin is, by displaying the rarity (Common, Uncommon, Rare, etc.) on a label. -
What is the issue?
I’m not really sure how to tackle this, seems like a confusing process. -
What solutions have you tried so far?
I have tried checking what table the current floor texture is in then changing the label’s text to that rarity, but it’s several different tables and I keep ending up in confusion.
Please provide your code so we have something to work with. Since the textures are located within tables, your solution is a good way to go about it
The code is pretty messy and incomplete, that’s why I didn’t post it, always been confused with for do loops. Here it is:
local floorTexture = workspace.Area.Platform.FloorTexture
local whiteBlackCheckers = "rbxassetid://6625549840"
local redBlackCheckers = "rbxassetid://6625569786"
local polkaDots = "rbxassetid://6625160551"
local woodPlanks = "rbxassetid://6657105968"
local grass = "rbxassetid://6661754477"
local common = {whiteBlackCheckers, redBlackCheckers, woodPlanks, grass}
local uncommon = {polkaDots}
local tiers = {common, common, uncommon}
for i, v in pairs(tiers) do
if floorTexture.Texture == common then
script.Parent.Text = "Rarity: Common"
elseif floorTexture.Texture == uncommon then
script.Parent.Text = "Rarity: Uncommon"
else
script.Parent.Text = "Rarity: Custom/None"
end
end
Explanation to your problem
Personally, instead of having separate rarity tables, I would have one rarity table, that contains all of your rarities, in their respective tables. This way it’s easier to work with given that you can loop over all of them, without them being separate.
Something like this:
local rarities = { -- table including smaller respective rarities
common = {whiteBlackCheckers, redBlackCheckers, woodPlanks, grass},
uncommon = {polkaDots},
rare = {}
}
When you loop over them, you can do:
for _, rarity in pairs (rarities) do -- loops through the whole table, which includes all of your rarities
-- returns 'common' table, 'uncommon' table, 'rare table
end
vs this:
local common = {whiteBlackCheckers, redBlackCheckers, woodPlanks, grass}
local uncommon = {polkaDots}
for _, rarity in pairs(common) do -- only one of your rarity tables can be looped over at a time
end
for _, rarity in pairs(uncommon) do -- much more redundant
end
local tiers = {'common', 'rare', 'uncommon'}
We need to make sure that whatever is in out tier table is also in our rarities table. The is due to the fact, that if we add a new ‘tier’ that doesn’t exist in our rarities table, the script will still find the other tiers’ within the table.
Essentially, now we’re going to find the tiers within the rarity table, if found, loop through the rarities, check if the floor texture is any one of those textures and then return the tier type that the texture was found in. Basically the tier type will be used as an index. We’re finding the value, then returning the index, which tells the rarity type.
Something like this:
local tiers = {'common', 'rare', 'uncommon'}
for i, rarity in pairs(tiers) do
if rarities[rarity] then -- if tiers are found within rarities table
for _, texture in pairs(rarities[rarity]) do -- looping through the rarity tables
if floorTexture.Texture == texture then -- checking texture
script.Parent.Text = "Rarity: " .. rarity
return rarity -- found rarity
else
if floorTexture.Texture ~= rarity then -- rarity not found (texture is not found)
script.Parent.Text = "Rarity: Custom/ None"
end
end
end
end
end
I have explained how you can go about this, but If you still don’t understand I will try to summarise as simple as I can with an example.
Looping through multiple tables are much easier when they’re within one entire table. Assuming that your iterator is checking each table, for something in common. Let’s say that you have a few tables, of different vehicles types. Each vehicle type has a different skin/ texture.
local BlueTexture = "rbxassetid://6625549840"
local RedTexture = "rbxassetid://6625569786"
local GreenTexture = "rbxassetid://6625160551"
local vehicles = {
Car = {BlueTexture},
Bus = {RedTexture},
Plane = {GreenTexture}
}
Pretty simple. right? Now, lets suppose we have a mysterious vehicle, that has a certain texture, but we do not know what vehicle type it’s.
MysterioVehicle = game.workspace.MysterioVehicle
Sure, we can just loop over our vehicles table, loop over the textures and check if the textures matches any specific vehicle type, and then return that vehicle type, however we may want to loop over specific vehicle types only.
We could use a placeholder table, like so:
local vechicleTypes = {'Car', 'Bus', 'Plane'}
, to compare to the vehicle table, and also use as a filter for what we want to look for in our vehicle table. Also it’s used to compare between both tables, so we can return the vehicle type.
for _, vehicle in pairs(vechicleTypes) do -- looping through our vehiclesTypes table
if vehicles[vehicle] then -- comparison between placeholder table and table
for _, texture in pairs(vehicles[vehicle]) do -- if placeholder exists with table, loop through texture
if MysterioVehicle.Texture == texture then -- comparison: if texture matches a texture within table, return the vehicle type (index)
print(vehicle)
return vehicle
else
if MysterioVehicle.Texture ~= vehicle then -- texture isn't found within the table, therefore index cannot be returned
print('mysterious vehicle is surely mysterious')
end
end
end
end
end
Hope this helps
Wow, thanks for such an in depth post. I halfway understand it, but I’m not sure what the script is supposed to look like as whole. Sorry for the late reply.
Nevermind, it works, it just doesn’t loop. Let me fix that.