I've been working on moving objects, and I wanted to know if I could anchor a car/train/bus/plane on the touch of a part? I know the script has to do with Functions, GetChildren, and more, but I couldn't figure out how to put them together into a script, can anyone help?
01 | -- make a variable of the model |
02 | myModel = game.Workspace:findFirstChild( "ModelName" ) |
03 |
04 | function onTouched(part) |
05 | if part.Parent:findFirstChild( "Humanoid" ) ~ = nil then |
06 | for _,item in pairs (myModel:GetChildren()) do |
07 | if item:IsA( "Seat" ) or item:IsA( "Truss" ) or item:IsA( "VehicleSeat" ) or item:IsA( "SpawnLocation" ) or item:IsA( "WedgePart" ) or item:IsA( "Part" ) or item:IsA( "BasePart" ) then |
08 | -- i've done this 'IF' because there might be scripts. If it's a classname with no such propertie as anchored it will break the script! |
09 | item.Anchored = true |
10 | wait( 10 ) |
11 | item.Anchored = false |
12 | end |
13 | end |
14 | end |
15 | end |
16 |
17 | script.Parent.Touched:connect(onTouched) |
If doesn't work, tell me output.
Hope this helped! Thanks, marcoantoniosantos3