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

A way to make a tool un-equip when you die?

Asked by 4 years ago

Is there a way to make a tool that you're holding unequip when you die?

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

local localPlayer = Players.LocalPlayer

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            if localPlayer.Character then 
                local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")
                if humanoid then 
                    humanoid:UnequipTools()
            print(player.Name .. " has died!")
                end
            end
        end

3 answers

Log in to vote
0
Answered by
palav 104
4 years ago

If your problem is that players are able to use a tool while they are dead(and before they respawn), then just check if the humanoids health is > 0 when they use the tool.

0
If the player dies. that makes them un-equip the tool. (since the tool doesn't function when the player dies) TheBuliderMC 84 — 4y
0
Alright. So what's the problem here? palav 104 — 4y
0
What i'm trying to do is that if a player dies, the tool that they're holding un-equips automatically. TheBuliderMC 84 — 4y
0
What you're telling me is that when a player dies, their tool is un-equipped. But then you're saying you're trying to make them unequip a tool when they die, which already happens? palav 104 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

You can use Humanoid.Died and Humanoid:UnequipTool to make the script works.


game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() character:WaitForChild("Humanoid"):UnequipTool(tool) -- change the tool becomes the tool's name end) end) end)

if this doesn't work for you, ask below the comment, or PM in my Roblox account! I'll be glad to help.

0
Also note: You'll automactially unequi[p tool if you died, sorry for spelling problems Xapelize 2658 — 4y
0
what do you mean "Change the tool becomes the tool's name". Where does the code belong? Local or Script? and if it's a script. Here's the error "UnequipTool is not a valid member of Humanoid" TheBuliderMC 84 — 4y
Log in to vote
0
Answered by 3 years ago

How do you do this. i have been reading this for like 1 or 2 hours but i cant seem to make it work

Answer this question