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

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

Asked by 4 years ago

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
0
Where are you getting character from on line 2? Why is createNewAnchor nested in another function and never called in this snippet? lukeh990 23 — 4y
0
The character variable is from player.CharacterAdded:Connect(function(character) NinjaMojo -3 — 4y
0
Re you using R6 or R15? lukeh990 23 — 4y
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? NinjaMojo -3 — 4y
View all comments (4 more)
0
What is createCharacterAnchors() returning? lukeh990 23 — 4y
0
My bad I have pasted the non-updated code in, I have made createNewAnchor() a non-local function and torsoCore = createNewAnchor NinjaMojo -3 — 4y
0
The createNewAnchor function is working, the code just breaks on line 20. NinjaMojo -3 — 4y
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 lukeh990 23 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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

0
How would I go about fixing that? NinjaMojo -3 — 4y
0
Since when I add the line "return part" I still get the same error. NinjaMojo -3 — 4y
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" NinjaMojo -3 — 4y
0
Do you think you could add more of the code? lukeh990 23 — 4y
Ad

Answer this question