See if a player is holding a tool

I’m creating a script that checks if a player is holding a tool, I sadly don’t know where to start. Here is what I have so far.

local animation = 000 
local Tool = player.Backpack:FindFirstChild("ToolName") 

game.Players.PlayerAdded:Connect(function(p)
while true do ---See if they are holding the part.


end


end)

Please note they spawn with the tool, so I just want to detect if they are holding it. If you know how please let me know. Thanks.

3 Likes

Check if [yourtoolhere].Equipped is true, if it is then run the code. Or use the event tools have,

tool.Equipped:Connect(function()
--Code
end)

tool.Unequipped:Connect(function()
--Code
end)
2 Likes

You can simply make a code inside the tool that connects the Equipped event of the tool to a function that does what you are wanting to do.

Then you should use a function called Equipped here is an example of it:

local Tool = player.Backpack:FindFirstChild("ToolName")
Tool.Equipped:Connect(function()
         print("Player is hold a tool")
end)
6 Likes

Is it possible to increase the player’s speed when they equip it? Sorta like a speed coil?

local animation = 000 
local Tool = player.Backpack:FindFirstChild("ToolName") 

game.Players.PlayerAdded:Connect(function(p)
Tool.Equipped:Connect(function()

---Speed boost.


end)
end)

It is possible just add

p:WaitForChild("Character").Humanoid.WalkSpeed = 32

Which basically waits for the character to spawn and then increases the walkspeed

2 Likes

Thanks. Could I use a function like this?

local animation = 000 
local Tool = player.Backpack:FindFirstChild("ToolName") 
local speed = 00 
game.Players.PlayerAdded:Connect(function(p)
Tool.Equipped:Connect(function()
plr.CharacterAdded:Connect(function(char)
			char.Humanoid.WalkSpeed = speed
		end)   

end)
end)
1 Like

Ah I’m seeing this now sorry for the late reply, that wouldn’t work since you are waiting for the character to be added, try this:

local animation = 000 
local Tool = player.Backpack:FindFirstChild("ToolName") 
local speed = 00 
game.Players.PlayerAdded:Connect(function(p)
Tool.Equipped:Connect(function()
			plr.Character.Humanoid.WalkSpeed = speed
		end)   
end)

You don’t need to wait for the character to be added as you can only equip a tool when it’s already loaded.

Thanks, I’m now having a different problem. The tool completely stops working when you reset. It will no longer give you speed. It’s a local script inside a tool. Here is the script I used:

local p = game:GetService("Players").LocalPlayer

local char = p.Character or p.CharacterAdded:Wait()

local hum = char:WaitForChild("Humanoid")

local defaultSpeed = hum.WalkSpeed

local customSpeed = 100 --How fast you want to go.

local Tool = script.Parent

Tool.Equipped:Connect(function()

hum.WalkSpeed = customSpeed

end)

Tool.Unequipped:Connect(function()

hum.WalkSpeed = defaultSpeed

end)

This worked for me:

local p = game:GetService("Players").LocalPlayer

repeat wait() until p.Character
local char = p.Character

local hum = char:WaitForChild("Humanoid")

local defaultSpeed = hum.WalkSpeed

local customSpeed = 100 

local Tool = script.Parent

Tool.Equipped:Connect(function()
	
	hum.WalkSpeed = customSpeed
	
end)

Tool.Unequipped:Connect(function()
	
	hum.WalkSpeed = defaultSpeed
	
end)

I just used another method of getting the character.

5 Likes