Why does the table not function properly?
I call the index function to index it, and when i print self.Zones in the indexing function it prints properly, but printing self.Zones in the :checkTables() function it prints an empty table.
local zoneFolder = workspace.Zones
local zone = {}
zone.Zones = {}
function zone:indexZones()
for _, zonePart in pairs(zoneFolder:GetChildren()) do
if not zonePart:IsA("BasePart") then return warn("zonePart", tostring(zonePart), "Doesn't Exist.") end
self.Zones[zonePart.Name] = {}
zonePart.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and self.Zones[zonePart.Name][player.UserId] ~= true then
self.Zones[zonePart.Name][player.UserId] = true
end
end)
zonePart.TouchEnded:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
self.Zones[zonePart.Name][player.UserId] = nil
end
end)
end
end
function zone:checkTables(location, id)
print(self.Zones) -- prints {}, Table doesn't include the zones indexed when :indexZone() is called.
if zone.Zones[location][id] == true then
return true
else
return false
end
end
return zone
here’s how i call it:
if not zoneModule:checkTables("House", plr.UserId) then