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

Why does it attempt to index nil with parent? [closed]

Asked by 3 years ago
Edited 3 years ago

Attempt To Index Nil With Parent

game.Players.PlayerAdded:Connect(function(plr)
    repeat wait() until plr.Character
    local character = plr.Character
    local Mimic = plr.Character:Clone()
    Mimic.Parent =  workspace
    Mimic.Head.Size = Vector3.new(10,10,10)
end)

Closed as Non-Descriptive by IAmNotTheReal_MePipe, User#32819, Cynical_Innovation, Leamir, Oxygen4Lyfe, WideSteal321, matiss112233, and raid6n

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

3 answers

Log in to vote
-4
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Example

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        print(character.Name.." character has loaded in")
    end)
end)
0
How come this comment got downvoted? L0RD_Bloxx -5 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Good question, it's because the character has its 'Archivable' property false by default. That means you shouldn't be able to clone it in the first place therefore when you attempted to clone the character, it gave you 'nil' or nothing in return and as we all know nothing has no parent.

Add this line before cloning the character: plr.Character.Archivable = true

Log in to vote
-4
Answered by 3 years ago
Edited 3 years ago

You need to do game.Workspace since the Workspace is inside of the game and also use the CharacterAdded function instead of the repeat wait.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
        local Mimic = plr.char:Clone()
            Mimic.Parent = game.Workspace
        Mimic.Head.Size = Vector3.new(10,10,10)
    end)
end)