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

How do I anchor something on touch of a part?

Asked by 9 years ago

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?

1 answer

Log in to vote
1
Answered by 9 years ago
-- 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

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

Answer this question