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'? PLEASE HELP ME!

Asked by 4 years ago

I've been working on a piggy game, and then my game broke and this error while playing with fan: attempt to index nil with 'Name'? please help me!

Thanks!

function module.DressPiggy(noob)
    local character

    if noob.EquippedSkin.Value ~= "" then
        if game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value) then
            character = game.ReplicatedStorage.Skins[noob.EquippedSkin.Value]:Clone()
        end
    else
        character = game.ReplicatedStorage.Skins.Noob:Clone()
    end
    character.Name = noob.Name

    noob.Character = character

    character.Parent = workspace
end
0
What line is this error on? User#31709 0 — 4y
0
line 11 please help me coreyhsGames 5 — 4y
0
What is "noob"? What is it, like a value, model, etc. User#31709 0 — 4y
0
To add on, what is "character" aswell? User#31709 0 — 4y
View all comments (3 more)
0
it's a model/skin for the noob coreyhsGames 5 — 4y
0
can u tell what the error is? hallmk7 50 — 4y
0
it probably means this returned nil game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value) HappyTimIsHim 652 — 4y

1 answer

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

The problem is you have the lines 11-15 outside of the if statement, so "character" is wiped. You can move those lines below character to fix it. Let me know if it fixes it!

Here's the modified code.

function module.DressPiggy(noob)
    local character

    if noob.EquippedSkin.Value ~= "" then
        if game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value) then
            character = game.ReplicatedStorage.Skins[noob.EquippedSkin.Value]:Clone()
        end
    else
        character = game.ReplicatedStorage.Skins.Noob:Clone()
    character.Name = noob.Name

    noob.Character = character

    character.Parent = workspace
    end
end
0
When I say wiped i mean like it cannot be defined by the script anymore. User#31709 0 — 4y
0
I'm kinda nooby at scripting, so could you update the script for me, thanks. coreyhsGames 5 — 4y
0
The character is not wiped, there is a `local character` on the first line of the function, which defines it out of that scope. xAtom_ik 574 — 4y
0
Yes, except it does not define the character. User#31709 0 — 4y
0
Please accept the answer if it works! User#31709 0 — 4y
Ad

Answer this question