How do i make a rarity gui?

So im trying to make a rarity gui, when a player kills the boss they get loot and depending on the loot they get the gui color would change for example if they got epic it would be purple or if they got legendary it would be yellow. And so im not sure how i can do that

local replicatedstorage = game:GetService("ReplicatedStorage")
local ArmorModule = require(game.ReplicatedStorage:WaitForChild("ArmorHandler"))
local remote = replicatedstorage.Events:WaitForChild("UpdateInventory")
local newArmor = ArmorModule.chooseRandom():Clone()

replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
	local template = script.Parent.MainGui.InventoryHolder.Inventory.Templates.Template
	local newTemplate = template:Clone()
	newTemplate.Parent = script.Parent.MainGui.InventoryHolder.Inventory.Duplicates

	
	local camera = Instance.new("Camera")
	local armorname = newArmor.Name
	local template2 = script.Parent.MainGui.Reward.Template
	local newTemplate2 = template2:Clone()
	newTemplate2.Parent =  script.Parent.MainGui.Reward
	
	camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
	camera.Parent = newTemplate2.VP
	newArmor.Parent = newTemplate2.VP
	newTemplate2.VP.CurrentCamera = camera
	script.Parent.MainGui.Reward.Visible = true
	newTemplate2.Visible = true
	wait(2)
	script.Parent.MainGui.Reward.Visible = false
	newTemplate2.Visible = false
	newTemplate.Visible = true
	
	camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
	camera.Parent = newTemplate.VP
	newArmor.Parent = newTemplate.VP
	newTemplate.VP.CurrentCamera = camera
	newTemplate:WaitForChild("ArmorName").Value = armorname
	newTemplate.Name = armorname
end)

Add a StringValue/Attribute to the armor, change color according to that

ill try that but how would i get this in a normal script

armormodule.armors = {
	["Legendary"] = {
		game.ReplicatedStorage.Armors.LegendaryArmor
	};

The table seems fine to put in a script

but how would i get the table in a normal script?

If the table is in a module just require the module via script

E.g.

module

local items = {

	["Legendary"] = {
		
		["ItemName1"] = {
			Property1 = true;
			Property2 = false;
		};

		["ItemName2"] = {
			Property1 = "sheesh";
			Property2 = 123;
		};

	};
	
	["AnotherRarity"] = {
		["ItemName1"] = {
			Property1 = true;
			Property2 = false;
		};
		
		["ItemName2"] = {
			Property1 = true;
			Property2 = false;
		};
	};

}

return items

script/localscript:

local RarityModule = require(--path to module)

local item = RarityModule["Legendary"]["ItemName1"] -- this return the first item.

-- then basically just find it through workspace or where it is via for loops;

for _,v in pairs(itemFolder:GetChildren()) do
	if v.Name == item then
		-- v is technically the physical object now, and just implement whatever here
		local cloneObject = v:Clone() -- clone the object so that it drops
		cloneObject.Parent == workspace -- this is an example of moving 
		-- then basically just do whatever with it
	end
end)

-- Now to get its properties/settings within the item you can do this;

 RarityModule["Legendary"]["ItemName1"]["Property1"]
--[[ now according to the module script, Property1 under 'ItemName1'
will return true.
]]

You can read up more about modules here.

2 Likes

what if there isn’t any property

	["Legendary"] = {
         game.ReplicatedStorage.Armors.LegendaryArmor
	};

You can try going by strings then let the script return a function replying with where the item is.

For example if the table was like this

["Legendary"] = {
	
	["FirstItem"],
	["AnotherItem"]
	
};

you can just do this in the main script:

local module = require(--[[ path module here ]] )
local ArmorFolder = game.ReplicatedStorage:FindFirstChild("Armors")

function grabItem(Item, Folder)
	local objItem
	
	for _, v in pairs(Folder:GetChildren()) do
		if v.Name == Item then
			objItem = v
		end
	end
	
	return objItem
end)

local Object = grabItem(module["Legendary"]["FirstItem"], ArmorFolder)

Object.Parent = workspace
-- etc etc etc

do i need that last part? Because i didn’t literally mean drop

local Object = grabItem(module["Legendary"]["FirstItem"], ArmorFolder)

Object.Parent = workspace

To grab the physical object in the folder you need

local Object = grabItem(module["Legendary"]["FirstItem"], ArmorFolder)
-- ^^ This will return the physical object in that folder.

Other than that, no you do not need to put it in the workspace.
That was only an example to show you how to use it.

How do i just get that “Legendary” Table instead of the things in it

Try taking a look at these, As this would help you the most:

Table Documentation
Examples of Utlizing Tables