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

Changing multiple parts properties sharing the same name?

Asked by
Burobuu 18
4 years ago

I have a script that is meant to stop a train(for a roller coaster) when it reaches the station for a brief moment. I have a property called active to prevent the function from running while already active. I have 5 MidCar body's and only 1 Lead car body. My script's function is to wait until the part(parent) is touched and to then anchor the entire train(using it's body's) for 10 seconds before letting the train continue moving again. I haven't tested the script yet but im not sure if it'll work due to the train having multiple duplicated Midcars. How can I change all 5 of the Midcars body's at once?

It's parent is just a normal block in the workspace called "Station"

Script

active=false

script.Parent.Touched:connect(function()
    if active == false then
  active=true
game.Workspace.DTrain.MilleniumLeadCar.BodyL.LeadBase.Anchored=true
game.Workspace.DTrain.MilleniumMidCar.Body1.Floor.Anchored=true
wait(10)
game.Workspace.DTrain.MilleniumLeadCar.BodyL.LeadBase.Anchored=false
game.Workspace.DTrain.MilleniumMidCar.Body1.Floor.Anchored=false
wait(10)
active=false
  end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hey, my name is Skydoeskey, and I am here to help you!

So if I am right. You want your parts in your model to become anchored. There's a very simple way of doing this. You can simply use the pairs function.

for _, object in pairs(game.Workspace.DTrain:GetChildren()) do
    object.Anchored = true
end

_ stands for the object number. object is the object name.

Get children collects all of the children inside of the model. Then the name of the object becomes anchored = true

If there are other models inside of your model then do this for each model

--Model 1
for _, object in pairs(game.Workspace.Model:GetChildren()) do
    if object.Name == "Part" then
    object.Anchored = true
end
end
--Model 2
for _, object in pairs(game.Workspace.Model.Model2:GetChildren()) do
    object.Anchored = true
end
    if object.Name == "Part2" then
        object.Anchored = true
end
--Model 3
for _, object in pairs(game.Workspace.Model.Model2:GetChildren()) do
    object.Anchored = true
end

This is not the best way to do it. But I have little time I have to go to work so I will help you when I come home

If this helped, feel free to accept this as an answer. If you have any other questions. Then please comment on my answer. I will answer as soon as possible. Have a nice day!

0
it said anchored it not a valid member of a model Burobuu 18 — 4y
0
Im guessing I should ungroup all the sub groups I have in the model Burobuu 18 — 4y
0
Are there any models inside of the model? Skydoeskey 108 — 4y
0
KK updated the post. Maybe this can help a little bit. Skydoeskey 108 — 4y
Ad

Answer this question