Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

2 comments

0
0

I only have 1 error saying Touched isn't a valid member of Model.

This discussion is preserved as it was. New answers, comments, and votes are closed.