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.

01local pname = game.Players.LocalPlayer
02print (pname)
03 
04 
05 
06local ch = game.Workspace.pname:Clone()
07 
08ch.Name = "character" ..name
09 
10ch.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
01-- I know what u want so here:
02-- Put all this in localscript
03 
04local Player = game.Players.LocalPlayer
05local Character = Player.Character or Player.CharacterAdded:Wait()
06 
07local NewCharacter = Instance.new('Model',game.ServerStorage)
08NewCharacter.Name = 'Character: ' ..Character.Name
09 
10for i,v in pairs(Character:GetChildren()) do
11    local NewItem = v:Clone()
12    NewItem.Parent = NewCharacter
13end
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:

01wait(1) -- Need to wait or else you'll get the nil error
02local players = game:GetService("Players")
03local p = players:WaitForChild("PlayerName")
04local plrName = tostring(p)
05print (plrName)
06local m = Instance.new("Model", game.Lighting) -- Model holding your player
07 
08--For loop that clones everything inside player and then parents it to the Model we made named "m"
09for _, v in pairs(p.Character:GetChildren()) do
10    v:Clone().Parent = m
11end
12m.Name = "Character"..plrName
13m:MakeJoints()

I hope this helped.

Answer this question