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

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

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

✓ Accepted answer

: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)

1 comment

0

This would fix that error

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