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?
✓ ANSWER ACCEPTED
How do I anchor something on touch of a part?
1 answer
✓ Accepted answer
-- make a variable of the model
myModel = game.Workspace:findFirstChild("ModelName")
function onTouched(part)
if part.Parent:findFirstChild("Humanoid") ~= nil then
for _,item in pairs(myModel:GetChildren()) do
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
-- 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!
item.Anchored = true
wait(10)
item.Anchored = false
end
end
end
end
script.Parent.Touched:connect(onTouched)
If doesn't work, tell me output.
Hope this helped! Thanks, marcoantoniosantos3
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
@Marc, just wondering, haven't tested it yet, but how do I make it unanchor itself after, let's say 10 seconds?
add under "item.Anchored = true", "delay(10, function() item.Anchored = false)
Also, @marcoantoniosantos3, you can shorten line 7 to "if item:IsA'BasePart' then"
try the new version