So, I'm trying to make some attachments for a rollercoaster system which I am currentley building but, the code is failing to create them and put them in the designated workspace.
01 | function SetupLiftHills() |
02 | local ChainAttachment 1 = Instance.new( "Attachment" ) |
03 | ChainAttachment 1. Name = "ChainAttachment1" |
04 | ChainAttachment 1. Parent = game.Workspace.Ride.Chains.LiftHill.Chain.Start |
05 | print ( "Created Successfully" ) |
06 |
07 | local ChainAttachment 2 = Instance.new( "Attachment" ) |
08 | ChainAttachment 2. Name = "ChainAttachment2" |
09 | ChainAttachment 2. Parent = game.Workspace.Ride.Chains.LiftHill.Chain.End |
10 | print ( "Created Successfully" ) |
11 | end |
I only typed this for executing the code and I feel that is where the problem is or it might be my code itself.
1 | SetupLiftHills() |
I am firing the code as I have added a statement right at the bottom of my code which specifies the function but, it doesn't appear to run at all.
Hello,
Maybe your Attachments are not parented to a Base-part, or you may have simply messed up your code, try using this code instead
1 | local Chain = game.Workspace.Ride.Chains.LiftHill.Chain |
2 |
3 | function SetUpLiftHills() |
4 | local Attachment 0 = Instance.new( "Attachment" , Chain.Start) -- Simpler |
5 | Attachment.Name = "ChainAttachment0" |
6 |
7 | local Attachment 1 = Instance.new( "Attachment" , Chain.End) |
8 | Attachment.Name = "ChainAttachment1" |
9 | end |
Activate Function
1 | SetUpLiftHills() |
If this doesn't work, check if End
and Start
are Parts or Not.
To Set A lot of Attachments:
Loop through all the Children in the Chain and give them attachments
1 | local Chain = game.Workspace.Ride.Chains.LiftHill.Chain |
2 |
3 | function SetUpLiftHills() |
4 | for Number, Chains in pairs (Chain:GetChildren()) do |
5 | local Attachment = Instance.new( "Attachment" , Chains) -- Simpler |
6 | Attachment.Name = "ChainAttachment" ..Number -- sets the names |
7 | end |
8 | end |
Activate function
1 | SetUpLiftHills() |