Script does not work, but has no errors

Hello guys, its been some days that i posted on the forum.
I have an issue, my script does not work and it has no error.
I have named the circles 1 - 9, all of them are sorted, and im making math.random so when u click some you lose (just change text to “:x:”).

I tried it with remote events and also local scripts and server scripts, none of them seem to work neither getting any errors from the console.

robloxapp-20220828-1910058.wmv (529.0 KB)

this is the vid inside studio, and the script is here:

local selCeasy = false
local selCmedium = false
local selChard = false
local client = game.Players.LocalPlayer
local aEasy = client.PlayerGui.MainUI.Main.TowerGame.easy:GetAttribute("selected")
local aMedium = client.PlayerGui.MainUI.Main.TowerGame.medium:GetAttribute("selected")
local aHard = client.PlayerGui.MainUI.Main.TowerGame.hard:GetAttribute("selected")

local function checkSelected()
	if aEasy == true then
		selCeasy = true
		selCmedium = false
		selChard = false
	end
	if aMedium == true then
		selCmedium = true
		selCeasy = false
		selChard = false
	end
	if aHard == true then
		selChard = true
		selCmedium = false
		selCeasy = false
	end
end

script.Parent.MouseButton1Click:Connect(function()
checkSelected()
wait(0.5)
if selCeasy == true then
	local tower1 = math.random(1, 3)
	local tower2 = math.random(4, 6)
	local tower3 = math.random(7, 9)
	client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower1).MouseButton1Click:Connect(function()
		client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower1).Text = "❌"
	end)
	client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower2).MouseButton1Click:Connect(function()
		client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower2).Text = "❌"
	end)
	client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower3).MouseButton1Click:Connect(function()
		client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower3).Text = "❌"
	end)
	end
end)	

Thanks for ur help!
Goodbye!

INFO: Buttons Easy, Medium and Hard have an Attribute. Its called “selected” and is a boolean. But in the client player gui and starter gui everything is deselected, even if i selected it with scripts.

example of the easy one:

local easy = script.Parent.Parent.easy:GetAttribute("selected")
local hard = script.Parent.Parent.hard:GetAttribute("selected")
local medium = script.Parent.Parent.medium:GetAttribute("selected")

local function clearAllAttributesExceptThisOne()
	hard = false
	script.Parent.Parent.hard.BackgroundColor3 = Color3.fromRGB(50, 61, 77)
	script.Parent.Parent.hard.Text = "Select hard"
	script.Parent.Parent.TowerHard.Visible = false
	medium = false
	script.Parent.Parent.medium.BackgroundColor3 = Color3.fromRGB(50, 61, 77)
	script.Parent.Parent.medium.Text = "Select medium"
	script.Parent.Parent.TowerMedium.Visible = false
end

script.Parent.MouseButton1Click:Connect(function()
	clearAllAttributesExceptThisOne()
	wait(.1)
	easy = true
	script.Parent.Parent.TowerEasy.Visible = true
	print("set to easy")
	script.Parent.BackgroundColor3 = Color3.fromRGB(75, 75, 255)
	script.Parent.Text = "Easy selected"
end)

It seems you’re setting the variables to a boolean and not the attributes. When you use :GetAttribute() or :GetAttributes() it returns a deepcopied version of the value, which means if the attribute changes then variable that you stored the gotten attribute to will not be changed. Every time you expect an attribute may have changed you’ll need to use ‘:GetAttribute()’ again.

local easy = script.Parent.Parent.easy

-- // setting the attribute so other scripts can read the change
easy:SetAttribute("selected", true) -- // Easy is now selected

--=== other script ===--

local aEasy = client.PlayerGui.MainUI.Main.TowerGame.easy

local function checkSelected()
	if aEasy:GetAttribute("selected") then
		selCeasy = true
		selCmedium = false
		selChard = false
	end
end
 -- // Etc. . .

I’m not sure if this helps but that’s all I’ve found so far.

I will try it in a few moments.

Omg thank you so much!
limitlimitlimitlimitlimitlimitlimitlimitlimit