script.Parent.OnServerEvent:Connect(function(plr) local clone1 = plr.Character:Clone() clone1.Parent = workspace clone1.HumanoidRootPart.Anchored = false clone1.HumanoidRootPart.CFrame = plr.Character.HumanoidRootPart.CFrame clone1.Name = plr.Name.."'s Clone" clone1.HumanoidRootPart.CFrame = clone1.HumanoidRootPart.CFrame game.Debris:AddItem(clone1,10) end)
this is my script and everytime i run it the error "attempt to index nil with parent" shows up and i dont know how to fix it
This is due to the fact that player characters are not Archivable by default. If an Instance is not archivable, something:Clone()
returns nil.
The solution would be to make the character archivable.
OnServerEvent:Connect(function(player) local character = player.Character character.Archivable = true local clone = character:Clone() -- etc end
Unfortunately, the only way to clone a character is to use Players:GetCharacterAppearanceAsync
or Players:GetCharacterAppearanceInfoAsync
. I'll shorten these to GetCharacter and GetCharacterInfo because they're hard to type.
GetCharacter returns a model full of these assets. Keep in mind that it does not return an NPC model. It returns the assets. So if you wanna get the Appearance, do this:
script.Parent.OnServerEvent:Connect(function(plr) local model = game.Players:GetCharacterAppearanceAsync(plr.UserId) --You need a UserId. model.Parent = workspace --Recommend you parent it to workspace to see the properties. This is only an example. end)
However, if you prefer a table, use GetCharacterInfo. However, it uses Dictionaries and sub-assets, which makes it harder to use. Don't recommend this one unless you don't wanna spam assets.
script.Parent.OnServerEvent:Connect(function(plr) local table = game.Players:GetCharacterAppearanceInfoAsync(plr.UserId) for i, v in pairs(table) do print(i , v) --Recommend you do to get the table of contents. end end)
Also, turning off Archivable may result in exploits on the client. So I don't recommend it at ALL.
Grab the player
from the actual location.
To grab a certain user to clone:
local plrModel = game.Workspace:WaitForChild("--input here")
To grab the player model:
local plrModel2 = game.Players.LocalPlayer:GetChildren()