Hello Roblox Devs,
I’m facing an issue in my project where I’m trying to display items in a GUI based on their rarity, with each rarity applying distinct visual effects (such as color changes, glow effects, etc.). However, despite following standard practices, I’m encountering several problems that prevent the system from functioning correctly.
Problem Description:
I have a system where players can view items in their backpack, which are categorized by rarity (Common, Uncommon, Rare, Epic, Mythical, Legendary). I’m trying to visual the weapon cells in order based on these rarities, how can I do that?.
I want to see first the weapons with Common, then Uncommon, Rare, Epic, Mythical, Legendary and lastly Unknown.
here’s how I see them at the moment (disordered)
Here’s my script:
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local items = {}
local buttons = {}
local EasyVisuals = require(game.ReplicatedStorage.EasyVisuals)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) – Disable the original backpack GUI
– Map of rarities to colors (updated with more vivid but slightly darker colors)
local rarityColors = {
Common = Color3.fromRGB(220, 220, 220), – Light gray
Uncommon = Color3.fromRGB(46, 139, 87), – Bright dark green
Rare = Color3.fromRGB(70, 130, 180), – Steel blue
Epic = Color3.fromRGB(148, 0, 211), – Intense purple
Mythical = Color3.fromRGB(139, 0, 0), – Dark red
Legendary = Color3.fromRGB(255, 215, 0), – Gold
Unknown = nil – No specific color
}
– Table to manage active effects
local activeEffects = {}
– Function to create a glow effect for Mythical
local function createIntenseGlowEffect(button)
local uiStroke = Instance.new(“UIStroke”)
uiStroke.Parent = button
uiStroke.Thickness = 4 – Thicker border
uiStroke.Color = Color3.fromRGB(255, 0, 0) – Intense red
uiStroke.Transparency = 0.1 – Nearly opaque
-- Pulsing effect
local tweenService = game:GetService("TweenService")
local tween = tweenService:Create(uiStroke, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
Transparency = 0.5 -- Transparency variation
})
tween:Play()
-- Additional light (Glow)
local lightEffect = Instance.new("ImageLabel")
lightEffect.Parent = button
lightEffect.BackgroundTransparency = 1
lightEffect.Size = UDim2.new(1.5, 0, 1.5, 0) -- Effect size
lightEffect.Position = UDim2.new(-0.25, 0, -0.25, 0) -- Central positioning
lightEffect.Image = "rbxassetid://2581284638" -- Glow image
lightEffect.ImageColor3 = Color3.fromRGB(255, 0, 0) -- Intense red
lightEffect.ImageTransparency = 0.6 -- Nearly transparent
-- Transparency animation for the glow
local glowTween = tweenService:Create(lightEffect, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
ImageTransparency = 0.8 -- Pulsing glow
})
glowTween:Play()
end
– Function to apply visual effects based on rarity
local function applyVisualsForRarity(button, rarityValue)
button.Name = rarityValue … “Button”
-- Remove previous effects
if activeEffects[button] then
activeEffects[button]:Destroy()
activeEffects[button] = nil
end
-- Basic configurations
button.BackgroundTransparency = 0.6 -- Semi-transparent background
button.ImageTransparency = 0.1 -- Weapon image is visible
-- Animated effect for background color
local tweenService = game:GetService("TweenService")
local originalColor = button.BackgroundColor3
-- Specific configurations for each rarity
if rarityValue == "Legendary" then
button.BackgroundColor3 = Color3.fromRGB(255, 223, 0) -- Light gold
local effect = EasyVisuals.new(button, "FireStroke", 0.5, 5, false, Color3.fromRGB(255, 69, 0))
activeEffects[button] = effect
elseif rarityValue == "Mythical" then
button.BackgroundColor3 = Color3.fromRGB(139, 0, 0) -- Dark red
createIntenseGlowEffect(button) -- Enhanced effect for Mythical
elseif rarityValue == "Epic" then
button.BackgroundColor3 = Color3.fromRGB(148, 0, 211) -- Intense purple
-- Subtle animation for Epic
local tween = tweenService:Create(button, TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
BackgroundTransparency = 0.5
})
tween:Play()
elseif rarityValue == "Rare" then
button.BackgroundColor3 = Color3.fromRGB(70, 130, 180) -- Steel blue
local stroke = Instance.new("UIStroke", button)
stroke.Thickness = 2
stroke.Color = Color3.fromRGB(135, 206, 250) -- Light blue
stroke.Transparency = 0.4
-- Pulsing effect for Rare
local tween = tweenService:Create(stroke, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
Transparency = 0.6 -- Transparency variation
})
tween:Play()
activeEffects[button] = stroke
elseif rarityValue == "Uncommon" then
button.BackgroundColor3 = Color3.fromRGB(46, 139, 87) -- Bright dark green
local stroke = Instance.new("UIStroke", button)
stroke.Thickness = 2
stroke.Color = Color3.fromRGB(124, 252, 0) -- Lime green
stroke.Transparency = 0.4
stroke.Parent = button
-- Animate the border for a pulsing effect
local tween = tweenService:Create(stroke, TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
Transparency = 0.6 -- Transparency variation
})
tween:Play()
activeEffects[button] = stroke
elseif rarityValue == "Common" then
button.BackgroundColor3 = Color3.fromRGB(220, 220, 220) -- Light gray
-- Subtle animation for the Common button
local tween = tweenService:Create(button, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true), {
BackgroundTransparency = 0.65
})
tween:Play()
else
-- Other or unknown rarities
button.BackgroundColor3 = rarityColors[rarityValue] or Color3.fromRGB(255, 255, 255)
end
end
– Function to refresh and create new buttons
function refresh(filteredItems)
– Remove old buttons
for _, v in pairs(buttons) do
v:Destroy()
end
buttons = {}
-- Create new buttons for each item
for i, v in pairs(filteredItems) do
local button = script.Sample:Clone()
button.Name = v.Name
button.LayoutOrder = i
button.Parent = script.Parent.Handler
button.Image = v.TextureId
local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(0, 10)
uiCorner.Parent = button
local rarity = v:FindFirstChild("Rarity")
if rarity and rarity:IsA("StringValue") then
applyVisualsForRarity(button, rarity.Value)
else
applyVisualsForRarity(button, "Unknown")
end
table.insert(buttons, button)
button.MouseButton1Click:Connect(function()
if script.Parent.Handler.Selected.Value == nil or script.Parent.Handler.Selected.Value ~= v then
script.Parent.Frame.ItemName.Text = v.Name
script.Parent.Frame.ImageLabel.Image = v.TextureId
local rarity = v:FindFirstChild("Rarity")
if rarity and rarity:IsA("StringValue") then
script.Parent.Frame.RarityItem.Text = rarity.Value
script.Parent.Frame.RarityItem.TextColor3 = rarityColors[rarity.Value] or Color3.fromRGB(255, 255, 255)
else
script.Parent.Frame.RarityItem.Text = "Unknown"
script.Parent.Frame.RarityItem.TextColor3 = Color3.fromRGB(255, 255, 255)
end
script.Parent.Handler.Selected.Value = v
if script.Parent.Handler.Selected.Value ~= script.Parent.Handler.Equipped.Value then
script.Parent.Handler.Location.Value = v.Parent
script.Parent.Frame.Equip.Text = "Equip"
else
script.Parent.Frame.Equip.Text = "Unequip"
end
end
end)
end
end
– Function for search
local function searchWeapons(query)
local filteredItems = {}
for _, v in pairs(items) do
if v.Name:lower():find(query:lower()) then
table.insert(filteredItems, v)
end
end
refresh(filteredItems)
end
– Add listener for the search TextBox
local searchBox = script.Parent.SearchFrame.TextBox
searchBox:GetPropertyChangedSignal(“Text”):Connect(function()
searchWeapons(searchBox.Text)
end)
function backpackRefresh()
items = {}
search(character)
search(player.Backpack)
refresh(items)
end
function search(location)
for _, v in pairs(location:GetChildren()) do
if v:IsA(“Tool”) then
table.insert(items, v)
end
end
end
player.Backpack.ChildAdded:Connect(backpackRefresh)
player.Backpack.ChildRemoved:Connect(backpackRefresh)
character.ChildAdded:Connect(backpackRefresh)
character.ChildRemoved:Connect(backpackRefresh)
backpackRefresh()
I’ve attached the relevant code below, and I’d be happy to provide further details if needed. Any help or suggestions would be greatly appreciated!
Thanks in advance!