Attribute true, still prints false

Hello there,
im making some sort of tower game and i have 2 attributes, isWrong and canBeSelected. Both are booleans. When i click the Confirm button it makes an math.random for each tiles that are numbered. (tile 4 Attribute isWrong = false, now when we get the new value returned so math.random(1, 3), math.random(4, 6) etc. and the 4 gets selected it sets the value isWrong to true, it works. If i press the wrong tile it reveals all tiles and u cant click any tiles anymore and sets all tiles attribute canBeSelected = false. But when i click a right one without pressing any wrong tile it prints out “You cant click this item!” (I made that if its not selected so it means its false even if its true))

This is the local script when you press confirm:

local selCeasy = false
local selCmedium = false
local selChard = false
local client = game.Players.LocalPlayer
local aEasy = client.PlayerGui.MainUI.Main.TowerGame.easy
local aMedium = client.PlayerGui.MainUI.Main.TowerGame.medium
local aHard = client.PlayerGui.MainUI.Main.TowerGame.hard

local function checkSelected()
	if aEasy:GetAttribute("selected", true) then -- // Easy is now selected then
		selCeasy = true
		selCmedium = false
		selChard = false
	end
	if aMedium:GetAttribute("selected", true) then
		selCmedium = true
		selCeasy = false
		selChard = false
	end
	if aHard:GetAttribute("selected", true) then
		selChard = true
		selCmedium = false
		selCeasy = false
	end
end

local function createTowerEasy()
	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):SetAttribute("isWrong", true)
	client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower2):SetAttribute("isWrong", true)
	client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:FindFirstChild(tower3):SetAttribute("isWrong", true)
end

local function refreshEasy()
	for i, v in pairs(client.PlayerGui.MainUI.Main.TowerGame.TowerEasy:GetChildren()) do
		v:SetAttribute("canBeSelected", true)
		v:SetAttribute("isWrong", false)
		v.Text = "⭕"
	end
end
local function createTowerMed()
	local tower11 = math.random(1, 3)
	local tower22 = math.random(4, 6)
	local tower33 = math.random(7, 9)
	local tower44 = math.random(10, 12)
	client.PlayerGui.MainUI.Main.TowerGame.TowerMedium:FindFirstChild(tower11):SetAttribute("isWrong", true)
	client.PlayerGui.MainUI.Main.TowerGame.TowerMedium:FindFirstChild(tower22):SetAttribute("isWrong", true)
	client.PlayerGui.MainUI.Main.TowerGame.TowerMedium:FindFirstChild(tower33):SetAttribute("isWrong", true)
	client.PlayerGui.MainUI.Main.TowerGame.TowerMedium:FindFirstChild(tower44):SetAttribute("isWrong", true)
end

local function refreshMed()
	for i, v in pairs(client.PlayerGui.MainUI.Main.TowerGame.TowerMedium:GetChildren()) do
		v:SetAttribute("canBeSelected", true)
		v:SetAttribute("isWrong", false)
		v.Text = "⭕"
	end
end


script.Parent.MouseButton1Click:Connect(function()
	checkSelected()
	wait(0.5)
	script.Parent.Active = false
	script.Parent.Text = "Confirmed"
	if selCeasy == true then
		refreshEasy()
		wait(.1)
		createTowerEasy()
	end
	if selCmedium == true then
		refreshMed()
		wait(.1)
		createTowerMed()
	end
end)	

And this is the code for each tile:

local num = math.random(1, 2.5) -- creates a int for multiplier you get when this is the right tile

local function revealTiles()
	for i, v in pairs(script.Parent.Parent:GetChildren()) do
		if v:GetAttribute("isWrong", true) then
			v.Text = "❌"
		elseif v:GetAttribute("isWrong", false) then
			v.Text = "💎 - "..num
			v:SetAttribute("canBeSelected", false)
		end
	end
end

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent:GetAttribute("isWrong", true) then
		script.Parent.Text = "❌"
		for i, v in pairs(script.Parent.Parent:GetChildren()) do
			v.Active = false
			wait(.01)
			revealTiles()
		end
	elseif script.Parent:GetAttribute("canBeSelected", false) then
		script.Parent.Active = false
		error("You cannot click this item!")
	elseif script.Parent:GetAttribute("isWrong", false) and script.Parent:GetAttribute("canBeSelected", true) then
		script.Parent.Text = "💎 - "..num
		game.Players.LocalPlayer.leaderstats["Trading Bucks"].Value = game.Players.LocalPlayer.leaderstats["Trading Bucks"].Value + num
	end
end)

Dont mind the medium, its just the clone with more tiles and not done, just focus on the easy tower game tiles.

It also shows true in studio in the player gui, not starter gui and the attribute canBeSelected is checked. But it still prints out (“You cant click this item”) so it means it says that its false. But it isnt!

Its very complicated but if you can help i would be happy!
Goodbye!

Why are you passing a second argument into to GetAttribute?
image
GetAttribute receives a single argument which is the attribute name.

Did you mean to do this?:

if script.Parent:GetAttribute("isWrong") == true then

elseif script.Parent:GetAttribute("canBeSelected") == false then

else --No need for an else if because it only reaches here if both isWrong is false and canBeSelected is true

end

Because it also works like that for me. Oh i didnt know that but it still works if not let me know

It shouldn’t work like that. The parameter does not exist.
Try changing all of your if statements to if something:GetAttribute(name) == value instead.

Are both codes local scripts?

Yes they are. Let me try that (I hate it when somethings wrong, now i gotta change like everything :expressionless:) but thanks!

Okay nvm it works, thank you so much!