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

How to make a player equip a tool which he had equipped before death?

Asked by
Soban06 410 Moderation Voter
3 years ago

Let's suppose a player equipped a tool 'x'. Now when he dies, I want that tool to be equipped again. So that the player does not have to continuously equip the tool every time he dies.

Here is my attempt:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local StarterGear = Player.StarterGear
local Backpack = Player.Backpack
local toolOnDeath = {}
wait(1)

Backpack.ChildRemoved:Connect(function(removedChild)
    if removedChild:IsA("Tool") then
        table.insert(toolOnDeath, removedChild)
    end
end)

Player.CharacterAdded:Connect(function()
    print("CharacterAdded")
    if toolOnDeath ~= nil then
        for i, v in pairs(toolOnDeath) do
            if v:IsA("Tool") then
                print("Tool is going to be equipped now")
                Character.Humanoid:EquipTool(v)
            end
        end
    end
end)

But this does not work. "Tool is going to be equipped now" prints but the humanoid does not equip the tool. Why?

Thanks for any help

0
You could just parent the tool to the player's character Spjureeedd 385 — 3y
0
I think it's because you are using local script? Feelings_La 399 — 3y
0
@Spjureeedd I tried that like this inside the CharacterAdded above the humanoid equip tool part: v.Parent = Character. But that does not do anything. Soban06 410 — 3y

Answer this question