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

How would I clone a character on spawn?

I have a clone character on spawn script but it gives me a "attempt to index local 'd' (a nil value)" error. How would I fix this? Here is my server script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(5)
		local d = char:Clone()
		d.Parent = game.Workspace
		
	end)
end)

2 comments

0

you would have to set char.Archivable to true first

0

Thank you

2 answers

✓ Accepted answer

Try this!

game.Players.PlayerAdded:Connect(function(plr) --player added
    plr.CharacterAdded:Connect(function(char)  --character added
        
        wait(5)
        char.Archivable = true  --it will return nil if the cloned object is not archivable
        local clone = char:Clone() 
        clone.Parent = game.Workspace --Put it in workspace

    end)
end)

I hope this worked!

5 comments

0

Doesn't solve the problem.

0

Doesn't????

0

Try yourself.

0

Thanks for accepting!

0

you need to explain the script. and after clone disable archivable

Problem

You forgot to set archivable of player to true You need to set true "Archivable" in player model for fix it. If archivable is false, you can't clone. if archivable is true, you can clone. Remember: All characters spawn with archivable false.

What archivable makes?

Determines if an Instance can be cloned using Instance:Clone or saved to file

Correction

For your code you need to set archivable of player to true, after clone set to false.

Example:

local obj = workspace.Model
Obj.Archivable = true
local clone = Obj:Clone()
clone.Parent = workspace
Obj.Archivable = false

Fixed script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(5)
		char.Archivable = true
		local d = char:Clone()
		d.Parent = game.Workspace
		char.Archivable = false
	end)
end)

Hope it helped :)

Wiki pages: Archivable


If works, not forgot to accept a answer or put [SOLVED] in title.

1 comment

0

do not, not just not

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