local part = game.Workspace.SpawnTruck local Occupants = {} local ArmyTruck = game.Workspace.ArmyTruck while true do for i,v in pairs(ArmyTruck:GetChildren()) do if v:IsA("VehicleSeat") then if v.Occupant ~= nil then table.insert(Occupants,v.Occupant.Parent) end end end print("There are "..#Occupants.." on this army truck right now.") if #Occupants == 5 then for i = 0,100,0.01 do script.Parent:TranslateBy(Vector3.new(i,0,0)) wait(0.05) end end wait() end
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:
-- [snip] end wait() Occupants = {} end
Perhaps more idiomatically, you could use a numerical value to count the occupants:
local part = game.Workspace.SpawnTruck local ArmyTruck = game.Workspace.ArmyTruck while true do local NumOccupants = 0 for i,v in pairs(ArmyTruck:GetChildren()) do if v:IsA("VehicleSeat") then if v.Occupant ~= nil then NumOccupants = NumOccupants + 1 end end end print("There are "..NumOccupants.." on this army truck right now.") if NumOccupants == 5 then for i = 0,100,0.01 do script.Parent:TranslateBy(Vector3.new(i,0,0)) wait(0.05) end end wait() end