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

attempt to index nil with 'Name'? PLEASE HELP ME!

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

7 comments

0

What line is this error on?

0

line 11 please help me

0

What is "noob"? What is it, like a value, model, etc.

0

To add on, what is "character" aswell?

0

it's a model/skin for the noob

0

can u tell what the error is?

0

it probably means this returned nil game.ReplicatedStorage.Skins:FindFirstChild(noob.EquippedSkin.Value)

1 answer

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

5 comments

0

When I say wiped i mean like it cannot be defined by the script anymore.

0

I'm kinda nooby at scripting, so could you update the script for me, thanks.

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.

0

Yes, except it does not define the character.

0

Please accept the answer if it works!

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