Here is what I have:
A inventory system that has rarities based on rolling them
Showcase:
Problem:
(Its supposed to return the selected rarity back when equipping sum else)
Script:
--██╗███╗░░██╗██╗░░░██╗███████╗███╗░░██╗████████╗░█████╗░██████╗░██╗░░░██╗
--██║████╗░██║██║░░░██║██╔════╝████╗░██║╚══██╔══╝██╔══██╗██╔══██╗╚██╗░██╔╝
--██║██╔██╗██║╚██╗░██╔╝█████╗░░██╔██╗██║░░░██║░░░██║░░██║██████╔╝░╚████╔╝░
--██║██║╚████║░╚████╔╝░██╔══╝░░██║╚████║░░░██║░░░██║░░██║██╔══██╗░░╚██╔╝░░
--██║██║░╚███║░░╚██╔╝░░███████╗██║░╚███║░░░██║░░░╚█████╔╝██║░░██║░░░██║░░░
--╚═╝╚═╝░░╚══╝░░░╚═╝░░░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝░░░╚═╝░░░
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local invgui = PlayerGui.Inventory.Frame
local newimagebutton = Instance.new("ImageButton")
newimagebutton.Parent = invgui
newimagebutton.BackgroundColor3 = Color3.new(100, 100, 0)
newimagebutton.Image = ItemImages[selectedRank]
newimagebutton.Name = selectedItem
newimagebutton.BorderSizePixel = 0
newimagebutton.ZIndex = 200
newimagebutton.BackgroundTransparency = 1
local EquippedButton = PlayerGui.Inventory.EquipPannel.EquippedButton
local nothingequipped = true
newimagebutton.MouseButton1Click:Connect(function()
local equippedbuttonimage = EquippedButton.Image
if nothingequipped == true then
print("nothing is equipped")
EquippedButton.Image = newimagebutton.Image
newimagebutton:Destroy()
nothingequipped = false
else
print("something is equipped")
local newbutton = Instance.new("ImageButton")
newbutton.Parent = invgui
newbutton.BackgroundColor3 = Color3.new(100, 100, 0)
newbutton.Image = equippedbuttonimage
newbutton.Name = selectedItem
newbutton.BorderSizePixel = 0
newbutton.ZIndex = 200
newbutton.BackgroundTransparency = 1
EquippedButton.Image = ""
nothingequipped = true
newbutton.MouseButton1Click:Connect(function()
EquippedButton.Image = newbutton.Image
newbutton:Destroy()
end)
end
end)
EquippedButton.MouseButton1Click:Connect(function()
if EquippedButton.Image == "" then
-- Do nothing if EquippedButton is empty
else
local newimagebutton = Instance.new("ImageButton")
newimagebutton.Parent = invgui
newimagebutton.BackgroundColor3 = Color3.new(100, 100, 0)
newimagebutton.Image = EquippedButton.Image
newimagebutton.Name = selectedItem
newimagebutton.BorderSizePixel = 0
newimagebutton.ZIndex = 200
newimagebutton.BackgroundTransparency = 1
EquippedButton.Image = ""
newimagebutton.MouseButton1Click:Connect(function()
EquippedButton.Image = newimagebutton.Image
newimagebutton:Destroy()
end)
end
end)
print("created")
else
print("Cooldown. Please wait before rolling again.")
end
end)
A lot of the variables are missing but they are infact defined in other parts of the script above this function