Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does the model not move when 5 players are seated?

Asked by 5 years ago
01local part = game.Workspace.SpawnTruck
02local Occupants = {}
03local ArmyTruck = game.Workspace.ArmyTruck
04while 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 
View all 25 lines...

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.

2 answers

Log in to vote
1
Answered by
gskw 1046 Moderation Voter
5 years ago

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 = {}
5end

Perhaps more idiomatically, you could use a numerical value to count the occupants:

01local part = game.Workspace.SpawnTruck
02local ArmyTruck = game.Workspace.ArmyTruck
03while 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 
View all 23 lines...
0
Why does it keep saying "There are 0 on this army truck right now?" BaconX112X 75 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

check the seats properties? This seems weird

Answer this question