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

How do i fix "attempt to call method 'clone' (a nil value)" in the script?

Asked by
130363 67
7 years ago
Edited 7 years ago

When I open the "Output" in the View tab. I shows me

"Players.Player1.PlayerGui..:Insert/CleanGui:..InsertFrame.CleanWorkspace.Script:2: attempt to call method 'clone' (a nil value)" in red

I want it to regenerate models in a folder but I don't know why it doesn't work. The folder is called Noobs and the models in the folder is called NPC.

model = game.Workspace.Noobs:GetChildren()
backup = model:clone()

function regenerate()                                                                        
    model:remove()                                    
    wait(2)                                                               

    model = backup:clone()
    model.Parent = game.Workspace                                                                                   
    model:makeJoints()
end


function onClick()
regenerate()
end

script.Parent.MouseButton1Click:Connect(onClick)

Thanks

I am new at scripting

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

:clone() should be capitalized since Lua is case-sensitive. that might fix it.

model = game.Workspace.Noobs:GetChildren(
backup = model:Clone()
function regenerate()                                                                       
    model:remove()                                   
    wait(2)                                                              
    model = backup:Clone()
    model.Parent = game.Workspace                                                                                  
    model:makeJoints()
end
function onClick()
regenerate()
end

script.Parent.MouseButton1Click:Connect(onClick)

0
This would fix that error shadownetwork 233 — 7y
Ad

Answer this question