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

How would I get a model to move if a certain amount of players are touching it?

Asked by 5 years ago

How would I get a model to move if there is a certain amount of players touching it? I'm trying to get a vehicle to move by itself when there are at least 5 players inside it.

This is the code I have so far, it gets the vehicle to move on its own:

for i = 0,100,.1 do
    script.Parent:TranslateBy(Vector3.new(i,0,0))   
    wait(.1)            
end

1 answer

Log in to vote
0
Answered by 5 years ago

This is what i would do:

while true do
local part = Your part
local Occupants = {}

part.Touched:Connect(function(hit)

 for i,v in pairs(hit.Parent.model:GetChildren()) do -- This is just an example of a model.
            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 vehicle")
    end

if #Occupants == 5 then

for i = 0,100,0.01 do
    script.Parent:TranslateBy(Vector3.new(i,0,0))
    wait(0.05)
    wait()
end 
end
end
end)

Im assuming that you mean that 5 players have to be seated in the model. I don't really know what you mean with "inside the vehicle."

I hope this helps, if this doesn't help just send a message.

0
If you don't know what Seat.Occupant is: https://developer.roblox.com/en-us/api-reference/property/Seat/Occupant BaconX112X 75 — 5y
0
I only have 1 error saying Touched isn't a valid member of Model. xItzDogey 4 — 5y
Ad

Answer this question