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

How do i copy players in workspace?

Asked by 3 years ago
for _, model in pairs(workspace:GetChildren()) do
            if model:IsA("Model") then
                for _, part in pairs(model:GetChildren()) do
                    if part:IsA("Humanoid") and not plr.Character.Humanoid then 
                        local copy = part.Parent:Clone()
                        copy.Parent = workspace
                        copy.HumanoidRootPart.CFrame = part.Parent.HumanoidRootPart.CFrame
                        game.Debris:AddItem(copy, 10)

                    end
                end

            end
        end

so here i tried to copy everything that had a humanoid in it and it doesnt work so idk what to do

2 answers

Log in to vote
1
Answered by 3 years ago

What Dev answered is almost correct, however it won't work since the character itself isn't archivable. Theres also a lot of unneccesary code, and ideally it can look as short as this:

for _, chars in pairs(workspace:GetChildren()) do
    if chars:FindFirstChild("Humanoid") and chars ~= plr.Character  then
        chars.Archivable = true
        local copy = chars:Clone()
        copy.Parent = workspace
        game.Debris:AddItem(copy, 10)
    end
end
  • All you have to do is check if theres an instance with a humanoid, and it isn't the plr's char
  • You have to make their character archivable before you copy it, otherwise you get an error
  • The copy will already have the same position as the instance it copies
0
- Also you might not even have to set the parent again, not sure if the clone still keeps the original's parent. SazaSensei 85 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
for _, model in pairs(workspace:GetChildren()) do
    if model:IsA("Model") then
        for _, part in pairs(model:GetChildren()) do
            if part:IsA("Humanoid") and not plr.Character.Humanoid then 
                local copy = part.Parent:Clone()

                copy.Archivable = true -- Archivable is turned off for all Player's Characters, you have to Enable it if you want to make a copy of a Character

                copy.Parent = workspace
                copy.HumanoidRootPart.CFrame = part.Parent.HumanoidRootPart.CFrame
                game.Debris:AddItem(copy, 10)

            end
        end

    end
end

hope this helps

Answer this question