Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 months ago
Edited 2 months 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 KBRM101, zamd157, 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 2 months 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 — 2mo
Ad
Log in to vote
1
Answered by 2 months 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 2 months ago
Edited 2 months 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)