Gui not working at all

I have this issue, with the code I am dealing with. GUI isn’t working when they got specific magic if not. it is set to “LOCKED” but if they do have it then “SELECT” and when using it set to “SELECTED”
I mostly need it to be LOCKED I am lost I got the rest afterwards.

screen shot on issue: https://gyazo.com/a5bb83fe187cf92e63ebc20c48175761 in screenshot it not supposed to be Select but locked then updated that magic to select if unlocked.

function getRarityColor(value)
	local color = Color3.fromRGB(255, 255, 255) -- Default color (white)
	if value == "Water" then
		color = Color3.fromRGB(0, 255, 255)
	elseif value == "Speed" then
		color = Color3.fromRGB(0, 255, 255)
	elseif value == "Bullet" then
		color = Color3.fromRGB(0, 255, 255)
	elseif value == "Healing" then
		color = Color3.fromRGB(0, 255, 255)
	elseif value == "Lightning" then
		color = Color3.fromRGB(85, 255, 0)
	elseif value == "Earth" then
		color = Color3.fromRGB(85, 255, 0)
	elseif value == "Fire" then
		color = Color3.fromRGB(85, 255, 0)
	elseif value == "Poison" then
		color = Color3.fromRGB(176, 88, 0)
	elseif value == "Sleep" then
		color = Color3.fromRGB(176, 88, 0)
	elseif value == "Gravity" then
		color = Color3.fromRGB(176, 88, 0)
	elseif value == "Wind" then
		color = Color3.fromRGB(176, 88, 0)
	elseif value == "King's Flame" then
		color = Color3.fromRGB(95, 0, 0)
	elseif value == "Foresight" then
		color = Color3.fromRGB(47, 0, 89)
	elseif value == "Iron Dragon Slayer" then
		color = Color3.fromRGB(255, 255, 56)
	elseif value == "Thunder Dragon Slayer" then
		color = Color3.fromRGB(255, 255, 56)
	elseif value == "Shadow Dragon Slayer" then
		color = Color3.fromRGB(255, 255, 56) 
	elseif value == "Fire Dragon Slayer" then
		color = Color3.fromRGB(255, 255, 56)
	elseif value == "Heavenly Body" then
		color = Color3.fromRGB(255, 255, 56)
	elseif value == "Ice-Make" then
		color = Color3.fromRGB(0, 0, 0)
	elseif value == "Water-Make" then
		color = Color3.fromRGB(0, 0, 0)
	else
		color = Color3.fromRGB(0, 0, 0)
	end
	return color
end

local player = game.Players.LocalPlayer
local selectedslot = game.ReplicatedStorage.PlayerData:FindFirstChild(player.Name):WaitForChild("SelectedSlot",math.huge)
local playerData = game.ReplicatedStorage.PlayerData:FindFirstChild(player.Name):WaitForChild("Slot"..selectedslot.Value,math.huge)
local PrimaryMagic = playerData:WaitForChild("Primary Magics")
local magicElement = playerData:WaitForChild("Element")

-- [[ Variables ]] --
local gui = script.Parent
local MainFrame = gui.Parent
local Main = MainFrame.Main
local MainName = Main:WaitForChild("Name")
local MagicStorage = MainName.MagicStorage

local InnerFrame = gui:WaitForChild("InnerFrame", math.huge)
local ScrollFrame = InnerFrame.ScrollingFrame
local ElementTable = {
	Common = {
		"Water",
		"Speed",
		"Bullet",
		"Healing",
	},
	Uncommon = {
		"Lightning",
		"Earth",
		"Fire",
	},
	Rare = {
		"Poison",
		"Sleep",
		"Gravity",
		"Wind",
	},
	Legendary = {
		"King's Flame",
	},
	Mythical = {
		"Foresight",	
	},
	Abnormal = {
		"Iron Dragon Slayer",
		"Thunder Dragon Slayer",
		"Shadow Dragon Slayer",
		"Fire Dragon Slayer",
		"Heavenly Body",

	},
	Unobtainable = {
		"Ice-Make",
	}
}

function updateState(state)
	for _, Button in pairs(ScrollFrame:GetDescendants()) do
		if Button:IsA("ImageLabel") then
			if PrimaryMagic:FindFirstChild(magicElement.Value) == true then
				Button.ImageColor3 = Color3.fromRGB(85, 255, 127)
			elseif PrimaryMagic:FindFirstChild(magicElement.Value) == false then
				Button.ImageColor3 = Color3.fromRGB(255, 0, 0)
			end
		end
		if Button:IsA("TextLabel") then
			if PrimaryMagic:FindFirstChild(magicElement.Value) == true then
				Button.Text = "SELECT"
			elseif PrimaryMagic:FindFirstChild(magicElement.Value) == false then
				Button.Text = "LOCKED"
			end
		end
	end
end

function resetButtonColors()
	for _, Button in pairs(ScrollFrame:GetDescendants()) do
		if Button:IsA("ImageLabel") then
			Button.ImageColor3 = Color3.fromRGB(85, 255, 127)
		end
		if Button:IsA("TextLabel") and Button.Name ~= "Element" then
			Button.Text = "SELECT"
		end
	end
end


local yPos = 5
local yOffset = 55

for _, magicName in pairs(ElementTable.Common) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label
	
	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset
	
	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Uncommon) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Rare) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Legendary) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Mythical) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Abnormal) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

for _, magicName in pairs(ElementTable.Unobtainable) do
	local Template = script.Template:Clone()
	local Inner = Template.Inner
	local Display = Inner.Element
	local Select = Inner.Select
	local Image = Select.Image
	local SelectDisplay = Image.Label

	Template.Parent = ScrollFrame
	Template.Position = UDim2.new(0.1, 0, 0, yPos)
	Template.Name = magicName
	Display.Text = magicName
	Display.TextColor3 = getRarityColor(Display.Text)
	yPos = yPos + yOffset

	Inner.Select.MouseButton1Down:Connect(function()
		updateState()
	end)
end

magicElement.Changed:Connect(function()
	local selectedMagic = magicElement.Value
	for _, Template in ipairs(ScrollFrame:GetChildren()) do
		if Template:IsA("Frame") then
			local Inner = Template.Inner
			local Display = Inner.Element
			local Select = Inner.Select
			local Image = Select.Image
			local SelectDisplay = Image.Label

			-- Check if the primary magics contain the selected magic
			local isPrimaryMagic = false
			for _, primaryMagic in ipairs(PrimaryMagic:GetChildren()) do
				if primaryMagic.Name == selectedMagic then
					isPrimaryMagic = true
					break
				end
			end

			updateState()
		end
	end
end)

game["Run Service"].Heartbeat:Connect(function()
	resetButtonColors()
	updateState()
end)

Please use a dictionary to improve readability…

ya just use a table for the values

2 Likes

Ignore that part of the code It nonsense code, I can easily do a table and that isn’t the issue it the stuff with SELECT, SELECTED, LOCKED