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

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

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

✓ Accepted answer

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()

4 comments

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.

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.

1

I will modify the answer for your needs

0

Appreciate it. Thank you very much :)

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