01 | local part = game.Workspace.SpawnTruck |
02 | local Occupants = { } |
03 | local ArmyTruck = game.Workspace.ArmyTruck |
04 | while true do |
05 |
06 | for i,v in pairs (ArmyTruck:GetChildren()) do |
07 | if v:IsA( "VehicleSeat" ) then |
08 | if v.Occupant ~ = nil then |
09 | table.insert(Occupants,v.Occupant.Parent) |
10 | end |
11 | end |
12 | end |
13 |
14 | print ( "There are " ..#Occupants.. " on this army truck right now." ) |
15 |
when 5 players are seated, i want the model to move, but the model doesn't move. Why does the model not move?
No errors from Roblox Studio.
The issue here is that every loop, your code is appending all occupants to the Occupants
table, but the table is never cleared. This means that the same occupant will appear multiple times in the table, and the table's length might never be 5. You want the end of your code to look like this:
1 | -- [snip] |
2 | end |
3 | wait() |
4 | Occupants = { } |
5 | end |
Perhaps more idiomatically, you could use a numerical value to count the occupants:
01 | local part = game.Workspace.SpawnTruck |
02 | local ArmyTruck = game.Workspace.ArmyTruck |
03 | while true do |
04 | local NumOccupants = 0 |
05 | for i,v in pairs (ArmyTruck:GetChildren()) do |
06 | if v:IsA( "VehicleSeat" ) then |
07 | if v.Occupant ~ = nil then |
08 | NumOccupants = NumOccupants + 1 |
09 | end |
10 | end |
11 | end |
12 |
13 | print ( "There are " ..NumOccupants.. " on this army truck right now." ) |
14 |
15 |