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)
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.