How to add a part into local character(workspace)?

Hello, I am very new to scripting and my skills are very low. And I have a problem, I need how to add some kind of box, or part for my game to the root part of a humanoid that will always be added once the character dies, so like in a local character in the workspace there will be a part with other parts of the character (rootpt, legs, arms) I wish i did describe the issue correctly. Thanks!

I recommend doing this using a gameHandler ServerSided script located in ServerScriptStorage.

Take the part you always want to add from some other location.
For now, I’ll assume the part is called “Extra” and located in ReplicatedStorage.

local RS = game:WaitForChild("ReplicatedStorage")
local extra = RS:WaitForChild("Extra")

-- this script adds the part ONLY to players
local function addExtraToPlr()
    for i,v in pairs (game.Workspace:GetDescendants()) do
        if v:IsA("Model") then
            local hum = v:FindFirstChildOfClass("Humanoid")
            if hum then
                if (game.Playery:GetPlayerFromCharacter(v) ~= nil) then
                    if not v:FindFirstChild("Extra") then
                        local c = extra:Clone()
                        c.Parent = v
                    end
                end
            end
        end
    end
end


-- Adds part to every entity containing a humanoid
local function addExtraToHum()
    for i,v in pairs (game.Workspace:GetDescendants()) do
        if v:IsA("Model") then
            local hum = v:FindFirstChildOfClass("Humanoid")
            if hum then
                if not v:FindFirstChild("Extra") then
                    local c = extra:Clone()
                    c.Parent = v
                end
            end
        end
    end
end

-- now decide for yourself what function you want to use, i will use the function adding the part just to players

addExtraToPlr() -- runs the function as soon as game starts
game.Workspace.ChildAdded:Connect(addExtraToPlr) -- runs when something gets added to workspace

This should work as far as I’m concerned but I didn’t try it out.

1 Like