Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

4 comments

0

If the player dies. that makes them un-equip the tool. (since the tool doesn't function when the player dies)

0

Alright. So what's the problem here?

0

What i'm trying to do is that if a player dies, the tool that they're holding un-equips automatically.

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?

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.

2 comments

0

Also note: You'll automactially unequi[p tool if you died, sorry for spelling problems

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"

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

This discussion is preserved as it was. New answers, comments, and votes are closed.