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

Player character Cloning ?

Asked by
truted1 21
7 years ago

Just wondering what I did wrong? it gives this error: 13:24:32.380 - Workspace.Script:6: attempt to call method 'Clone' (a nil value) If I dont use the pname and put my name in it works fine.

local pname = game.Players.LocalPlayer
print (pname)



local ch = game.Workspace.pname:Clone()

ch.Name = "character" ..name

ch.Parent = game.Lighting 


thanks for helping anyways.

0
Is this a Server Script or LocalScript? YouSNICKER 131 — 7y
0
This can be either i guss. Its just when a player joins it make a copy of the olayer truted1 21 — 7y

2 answers

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
7 years ago
Edited 7 years ago
-- I know what u want so here:
-- Put all this in localscript

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local NewCharacter = Instance.new('Model',game.ServerStorage)
NewCharacter.Name = 'Character: ' ..Character.Name

for i,v in pairs(Character:GetChildren()) do
    local NewItem = v:Clone()
    NewItem.Parent = NewCharacter
end

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

When using LocalPlayer it needs to be in a LocalScript. Also, for some reason you cannot clone the player model because I think by default it's Archivable value is set to false so you can make a for loop to go through and clone everything inside the player model. Here is my version of your code though that does work:

wait(1) -- Need to wait or else you'll get the nil error
local players = game:GetService("Players")
local p = players:WaitForChild("PlayerName")
local plrName = tostring(p)
print (plrName)
local m = Instance.new("Model", game.Lighting) -- Model holding your player

--For loop that clones everything inside player and then parents it to the Model we made named "m"
for _, v in pairs(p.Character:GetChildren()) do
    v:Clone().Parent = m
end
m.Name = "Character"..plrName
m:MakeJoints()

I hope this helped.

Answer this question