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!

01function module.DressPiggy(noob)
02    local character
03 
04    if noob.EquippedSkin.Value ~= "" then
05        if game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value) then
06            character = game.ReplicatedStorage.Skins[noob.EquippedSkin.Value]:Clone()
07        end
08    else
09        character = game.ReplicatedStorage.Skins.Noob:Clone()
10    end
11    character.Name = noob.Name
12 
13    noob.Character = character
14 
15    character.Parent = workspace
16end
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.

01function module.DressPiggy(noob)
02    local character
03 
04    if noob.EquippedSkin.Value ~= "" then
05        if game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value) then
06            character = game.ReplicatedStorage.Skins[noob.EquippedSkin.Value]:Clone()
07        end
08    else
09        character = game.ReplicatedStorage.Skins.Noob:Clone()
10    character.Name = noob.Name
11 
12    noob.Character = character
13 
14    character.Parent = workspace
15    end
16end
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