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

How do I anchor something on touch of a part?

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

✓ 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

4 comments

0

@Marc, just wondering, haven't tested it yet, but how do I make it unanchor itself after, let's say 10 seconds?

1

add under "item.Anchored = true", "delay(10, function() item.Anchored = false)

1

Also, @marcoantoniosantos3, you can shorten line 7 to "if item:IsA'BasePart' then"

0

try the new version

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