How to get an attribute from a table index

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello, I want to iterate through a table that has a column with spaces, check their ‘Occupied’ Attribute to see if it is occupied, and if it isn’t, change the space’s transparency and color to mark it as a player’s find 4 puck for their turn

  2. What is the issue? Include screenshots / videos if possible!
    I keep getting an error that says 'attempt to call missing method of GetAttribute of table whenever I try and access the currently selected index’s attribute

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking on the Dev forums and the api relating to tables, I did see one called ‘table.foreach’, that I thought would’ve worked, but I realized it is deprecated when I attempted to put it in the code.
    I’ve also tried using ‘GetChildren’ and ‘GetDescendants’ with the same error. Before switching to attributes, I also attempted to get a boolvalue child under each space as well, but that also results in the same error.

Here is the code as it currently stands:

--Variables
local clickdetector = script.Parent.ClickDetector
local Column = script.Parent
local debounce = false
local Player = game.Workspace.PlayerTurn
local CPU = game.Workspace.CPUTurn
SelectedColumn = Column.SelectedColumn
local Spaces = {
		Space1 = Column.Space1, 
		Space2 = Column.Space2, 
		Space3 = Column.Space3,
		Space4 =	 Column.Space4
}

clickdetector.MouseClick:Connect(function()
if not debounce then
SelectedColumn.Value = true
for k,v in pairs (Spaces) do
			local CheckOccupied = Spaces:GetAttribute("Occupied")
			print("Check1")
if false then
Spaces:SetAttribute("Occupied", true)
if Player then
print("Check3")
Spaces.Transparency = 0
Spaces.BrickColor = Spaces.BrickColor.new ("Bright Blue")
else
Spaces.Transparency = 0
Spaces.BrickColor = Spaces.BrickColor.new("Persimmon")
						end
					end
				end
			end
		end)

Also, here is what it looks like in the explorer and a visual representation in game

rblxexplorer1

1 Like

Why are you trying to get an attribute from a table?, You have to get the attribute from each so instead of Spaces:GetAttribute() it should be v:GetAttribute(),
also why is if false then, that’s just never going to run, i’m gonna assume you mean if GetAttribute returns true that run, in that case you have to change false to the v:GetAttribute()==false.

Sorry if i’m missunderstanding anything.

I was trying to get it for a table so i could check each one, then place the puck in the first one that returns false, and the ‘if false then’ was there to check the attribute

You can’t check the entire table you check every instance in that table one by one with the for loop the second argument of the for loop is the instance,
and the computer doesn’t know that you mean if the attribute means false, you have to tell it what has to be true that’s why i said v:GetAttribute(),
telling the computer if false will just means that everything inside that if statement will never run

If you want a table of the results of the attributes you can declare an empty table beforehand and then put any true one inside of that table

sorry for bump post but i was searching for an answer myself and eventually came up with my own solution being the only option sadly…

  local player = game.Players.LocalPlayer
  local playerAttributes = player:GetAttributes()
  for _, attribute in pairs(playerAttributes) do
  	player:GetAttributeChangedSignal(attribute):Connect(function(value)
  	print(value)
  end)

Hope this helps!! :grinning: :grinning:

1 Like