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

"Attempt to index nil with 'Name'" how do I fix this?

I'm getting this error when I try and change the part properties through the function - line 20. Any help would be appreciated.

function createCharacterAnchors()
	torso = character:WaitForChild("Torso")
	if torso ~= nil then
		print("found")
		local function createNewAnchor()
			print("started")
			local part = Instance.new("Part")
			part.Transparency = 1
			part.CanCollide = false
			part.FormFactor = Enum.FormFactor.Custom
			part.Size = 0.2 * Vector3.new(1, 1, 1)
			part.TopSurface = Enum.SurfaceType.Smooth
			part.BottomSurface = Enum.SurfaceType.Smooth
			part.Parent = character
				end
			end
		end

		local torsoCore 	= createCharacterAnchors()
			torsoCore.Name 	= "TorsoCore"
			local torsoCoreMotor 		= createNewMotor()
				torsoCoreMotor.Name 	= "TorsoCore"
				torsoCoreMotor.C0 		= CFrame.new(0, 0.5, 0) * CFrame.Angles(0, 		math.pi, 0)
				torsoCoreMotor.Part0 	= character.Torso
				torsoCoreMotor.Part1 	= torsoCore

8 comments

0

Where are you getting character from on line 2? Why is createNewAnchor nested in another function and never called in this snippet?

0

The character variable is from player.CharacterAdded:Connect(function(character)

0

Re you using R6 or R15?

0

I'm using R6, I think the issue stems from line 20 - can I not name the part that the function creates outside of the function?

0

What is createCharacterAnchors() returning?

0

My bad I have pasted the non-updated code in, I have made createNewAnchor() a non-local function and torsoCore = createNewAnchor

0

The createNewAnchor function is working, the code just breaks on line 20.

0

On line 20 there is nothing to modify because it does not look like your returning the object so It can't modify it

1 answer

✓ Accepted answer

It does not look like createCharacterAnchors() returns anything so you'd have to add a return to the function

4 comments

0

How would I go about fixing that?

0

Since when I add the line "return part" I still get the same error.

0

I don't know if I'm doing it wrong though, as I am getting an error when I call createNewAnchor() on line 19, saying "attempt to call a nil value"

0

Do you think you could add more of the code?

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