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

Why isn't my code producing the attachments which are required?

Asked by 1 year ago

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.

function SetupLiftHills()
    local ChainAttachment1 = Instance.new("Attachment")
    ChainAttachment1.Name = "ChainAttachment1"
    ChainAttachment1.Parent = game.Workspace.Ride.Chains.LiftHill.Chain.Start
    print("Created Successfully")

    local ChainAttachment2 = Instance.new("Attachment")
    ChainAttachment2.Name = "ChainAttachment2"
    ChainAttachment2.Parent = game.Workspace.Ride.Chains.LiftHill.Chain.End
    print("Created Successfully")
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.

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.

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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

local Chain = game.Workspace.Ride.Chains.LiftHill.Chain

function SetUpLiftHills()
    local Attachment0 = Instance.new("Attachment",  Chain.Start) -- Simpler
    Attachment.Name = "ChainAttachment0"

    local Attachment1 = Instance.new("Attachment",  Chain.End)
    Attachment.Name = "ChainAttachment1"
end

Activate Function

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

local Chain = game.Workspace.Ride.Chains.LiftHill.Chain

function SetUpLiftHills()
    for Number, Chains in pairs(Chain:GetChildren()) do
        local Attachment = Instance.new("Attachment",   Chains) -- Simpler
        Attachment.Name = "ChainAttachment"..Number -- sets the names
    end
end

Activate function

SetUpLiftHills()
0
Excellent news, the code you provided has fixed my problem. I have modified the code slightly but, it still prodcues the results I needed. Thank you again and I've marked you as the solution to the question. iiMxtt_Destinyii 62 — 1y
0
I do have a query though as I need to create quite a lot of attachments for this ride system. Is there an easier solution to creating attachments? Instead of creading seperate statements to create attachments. iiMxtt_Destinyii 62 — 1y
1
I will modify the answer for your needs Hi_People1133 218 — 1y
0
Appreciate it. Thank you very much :) iiMxtt_Destinyii 62 — 1y
Ad

Answer this question