I have a function that iterates through all of the chairs in a game to see whether or not a person is sitting in one. However, the Seat.Occupant value isn’t showing up correctly.
Here’s my code:
local function returnOccupiedSeats() -- Returns seats that are occupied by players in the round
-- Check all of the seats to see if they are currently occupied (ignore seats that are not)
for i, v in ipairs(game.Workspace.Objects.Chairs:GetChildren()) do -- Iterate through all the chair objects
if v.Seat.Occupant ~= nil then
print(v);
table.insert(seatOccupiedArray, v);
print(seatOccupiedArray[1]);
end
end
end
And then in my Chairs folder I have a bunch of chairs, but this is basically the skeleton of it:
Chair → Seat
So if I wanted to call the Seat of that chair, I would say Chair.Seat, if that makes any sense.
Yep. It is inside an infinite loop. However, I have a question.
Does putting an object inside two different tables affect that object itself? For example:
local array1 = {};
local array2 = {};
local test = game.Workspace.Objects.Characters:GetChildren("Bunny");
table.insert(array1, test);
table.insert(array2, test);
Edit: Meant to say:
local test = game.Workspace.Objects.Characters:FindFirstChild("Bunny");
I am kinda confused about what you mean affects? The table.insert function is going to insert your instance (in your example) inside of a specific table which you declared, at the same time it’s going to check the minimum index which in table is not equals to nil and set the instance there.
Also, the GetChildren function doesn’t have any parameters it just return an array of childrens inside of specific child.
How about if I were to change the Bunny’s name in x and y?
Say:
x.Name = "Hello";
y.Name = "Bye";
Would Bunny’s original name be equal to Bye? or would it stay as Bunny?
Sorry if I’m asking too many questions. This is what I basically did with my Chair objects. I have two different arrays that I’ve been pulling the Chair objects into and am wondering if doing that affected anything.
It depends which objects you have declared inside array. In your example there are two different indexes x and y. In case that both indexes in this array contains same object then correct the name would be Bye else two different objects would change names.