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

How to properly parent a clone?

Hello I'm trying to clone a trail to stay on a character and it isn't doing it giving the message "attempt to index nil with 'Clone'". I know it has something to do with parenting but i cant seem to find the issue.

Code in question:

		local trailCopy = Trail:Clone()
		trailCopy.Parent = character.Head

full code:

local ServerStorage = game:GetService("ServerStorage")
local Trail = ServerStorage:FindFirstChild("Trial")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		
		local trailCopy = Trail:Clone()
		trailCopy.Parent = character.Head
		
		local att0 = Instance.new("Attachment", character.Head)
		att0.Name = "att0"
		
		local att1 = Instance.new("Attachment", character.HumanoidRootPart)
		att1.Name = "att1"
		
		trailCopy.Attachment = att0
		trailCopy.Attachment = att1
		
		trailCopy.Enabled = true
	end)
end)

1 answer

The problem is that Trail does not exist or has probably not loaded yet.

You can use ServerStorage:WaitForChild("Trial") for it to wait for the child to load in.

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