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

Dropping backpack on death / Positioning them to the character's HumanoidRootPart Position?

Asked by 6 years ago

This is what I tried to make but failed:

--I located the character so no worries.

char.Humanoid.Died:connect(function()
    local plr = game.Players:GetPlayerFromCharacter(char)
    for i,v in pairs(plr.Backpack:GetChildren()) do
        v.Handle.Position = char.HumanoidRootPart.Position --Sad face
        v.Parent = workspace
    end
end)

The thing here is that I want the player to drop everything he/she has in their backpack. But Positioning the Handle won't help. Neither is positioning the whole tool because there is no function for that. Any help?

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

I’m not sure if there is a simpler way, but you could try putting each tool inside a model that you position at the character, and then moving the tool back outside the model once it’s been positioned.

char:WaitForChild("Humanoid").Died:Connect(function()
    local plr = game.Players:GetPlayerFromCharacter(char)
    for _,tool in pairs(plr.Backpack:GetChildren()) do
        if tool:IsA("Tool") and tool:FindFirstChild("Handle") then
            local positionModel = Instance.new("Model")
            tool.Parent = positionModel
            positionModel.PrimaryPart = tool.Handle
            positionModel:MoveTo(char.HumanoidRootPart.Position)
            tool.Parent = workspace
            positionModel:Destroy()
            -- re-welding my be required here
        end
    end
end)
Ad
Log in to vote
0
Answered by 6 years ago

I've found a really nice way to do it on my own.

But thanks for the help! I'll accept your answer

0
I'd be interested in what your way involves mattscy 3725 — 6y

Answer this question