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
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.

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:

    -- [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 
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