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.
01 | local pname = game.Players.LocalPlayer |
02 | print (pname) |
03 |
04 |
05 |
06 | local ch = game.Workspace.pname:Clone() |
07 |
08 | ch.Name = "character" ..name |
09 |
10 | ch.Parent = game.Lighting |
thanks for helping anyways.
01 | -- I know what u want so here: |
02 | -- Put all this in localscript |
03 |
04 | local Player = game.Players.LocalPlayer |
05 | local Character = Player.Character or Player.CharacterAdded:Wait() |
06 |
07 | local NewCharacter = Instance.new( 'Model' ,game.ServerStorage) |
08 | NewCharacter.Name = 'Character: ' ..Character.Name |
09 |
10 | for i,v in pairs (Character:GetChildren()) do |
11 | local NewItem = v:Clone() |
12 | NewItem.Parent = NewCharacter |
13 | end |
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:
01 | wait( 1 ) -- Need to wait or else you'll get the nil error |
02 | local players = game:GetService( "Players" ) |
03 | local p = players:WaitForChild( "PlayerName" ) |
04 | local plrName = tostring (p) |
05 | print (plrName) |
06 | local 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" |
09 | for _, v in pairs (p.Character:GetChildren()) do |
10 | v:Clone().Parent = m |
11 | end |
12 | m.Name = "Character" ..plrName |
13 | m:MakeJoints() |
I hope this helped.