Attribute Values are Printing Blank even with Values?

So I am new to using tables, as previously I was mostly using variables, and tables for only datastores, but currently I want a for loop to check if an attribute to a part contains the Player Name, but when testing to see the output of the table values, the values were all blank. I am unsure if I am not properly creating values in the table, but help would be grateful.

--Plots
local Plots = 
{
Plot1 = game.Workspace.Plot1.Ownership:GetAttribute("Owner"),
Plot2 = game.Workspace.Plot2.Ownership:GetAttribute("Owner"),
Plot3 = game.Workspace.Plot3.Ownership:GetAttribute("Owner"),
Plot4 = game.Workspace.Plot4.Ownership:GetAttribute("Owner"),
Plot5 = game.Workspace.Plot5.Ownership:GetAttribute("Owner")
}

local function OnStart()
	for i,v in pairs(Plots) do
		if v == Player.LocalPlayer.Name then
			print(v)
		end
	end
end

BuildButton.MouseButton1Click:Connect(OnStart)

Player here is not defined. Also you cannot use LocalPlayer in a server script. If its a localscript then use game.Players.LocalPlayer.Name instead.

I already defined the services above, I just didn’t include them in the code for simplicity sake.

When I print the Table of the values after the values had already changed, this is the output:

{
[“Plot1”] = “”,
[“Plot2”] = “”,
[“Plot3”] = “”,
[“Plot4”] = “”,
[“Plot5”] = “”
}

Use Instance | Roblox Creator Documentation because those plots may not have been replicated to the client yet.

Are the attributes equal to anything?

I think this should work:

local function OnStart()
local Plots = 
{
Plot1 = game.Workspace.Plot1.Ownership:GetAttribute("Owner"),
Plot2 = game.Workspace.Plot2.Ownership:GetAttribute("Owner"),
Plot3 = game.Workspace.Plot3.Ownership:GetAttribute("Owner"),
Plot4 = game.Workspace.Plot4.Ownership:GetAttribute("Owner"),
Plot5 = game.Workspace.Plot5.Ownership:GetAttribute("Owner")
}
	for i,v in pairs(Plots) do
		if v == Player.LocalPlayer.Name then
			print(v)
		end
	end
end

BuildButton.MouseButton1Click:Connect(OnStart)

If the attribute when you stored it in the table was not set to anything, then that is why it happens.
So you have to get the attribute when that function is called.

1 Like

Yes Player’s name when I touch the specific object.

You are correct, thank you so much, I hate when I forget about these things :grinning_face_with_smiling_eyes: