Text's aren't updating to correct value's

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” it due to, Bool Values from Primary Magics Folder, which has magic’s name after them and if set to false then Text is “LOCKED” ect. SetMagic is magicElement value

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.

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 magicElement = playerData:WaitForChild("Element")
local PrimaryMagic = playerData:WaitForChild("Primary Magics")

function updateButtonAppearance(buttonLabel, textLabel, SetMagic)
	local buttonText = ""
	local buttonColor = Color3.new()

	local magicElementValue = SetMagic
	local magicChild = PrimaryMagic:FindFirstChild(magicElementValue)

	if magicChild and magicChild.Value == true then
		buttonText = "SELECT"
		buttonColor = Color3.fromRGB(85, 255, 127) -- Green
	elseif magicChild and magicChild.Value == false then
		buttonText = "LOCKED"
		buttonColor = Color3.fromRGB(255, 0, 0) -- Red
	end

	buttonLabel.ImageColor3 = buttonColor
	textLabel.Text = buttonText

	resetButtonColors()
end