How do I check if a player is holding an tool?

WARNING!!! I do not need to check whether the item is in the player’s inventory, I need to know if the player is holding the item.

I am writing a combat system and need a player to strike, etc. only if he is holding the combat. What’s the best way to do it?

Where your script located? If it is in tool then:

local tool = script.Parent
tool.Equipped:Connect(function()
   --put code you want
end)

At the moment my script is in the starter player - character

And by the way, when I tried this option and wrote a print inside the function, then just nothing came out neither when he holds the item nor when he just logs into the game

In starter character scripts or in starter player scripts?

in the starter character. Wait… in the starter player will better or what?

Parent the LocalScript to the tool.

Just asking,it is necessary to know script location in 90% cases.

Okay then, sorry I didn’t get it right away. yes the script is currently in the starter character

Ok, so here is code:

local character = script.Parent.Parent
local tool = character:WaitForChild("PUTHERETOOLNAME")
tool.Equipped:Connect(function()
        --put here your code--
end)
local player = script.Parent.Parent
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local tool = game.Players.LocalPlayer.Backpack:FindFirstChild("Combat")  or player.Character:FindFirstChild("Combat")

tool.Equipped:Connect(function()
	print("Equipped")
end)

tool.Unequipped:Connect(function()
	print("Unequipped")
end)

See, it’s my script . I have the problem because in her nothing printing…

By the way, what country are you from, if it’s no secret) Just that you have the flag of my country on your skin

1 Like

Just make it

local tool = script.Parent

Add boolean called playerequippedtool into script and then try to use this:

local Eqquiped = script.playerequippedtool.Value
game:GetService("Players").PlayerAdded:Connect(function(Player)
       Player.CharacterAdded:Connect(function(Character)
           local function ToolParent()
              if Character:FindFirstChild("Combat") then
               Eqquiped = true
              elseif  Player:WaitForChild("Backpack"):WaitForChild("Combat") then
                 Eqquiped = false
              end
             end
             Player:WaitForChild("Backpack"):WaitForChild("Combat"):GetPropertyChangedSignal("Parent"):Connect(ToolParent)
       end)
end)
local function Eqquipedfunc()
        if Eqquiped == true then
      --your code here--
    end
end
script.playerequippedtool:GetPropertyChangedSignal("Value"):Connect(Eqquipedfunc)

try this script

local function Check(Tool) --Tool is name of the tool
	if game.Players.LocalPlayer.Character:FindFirstChild(Tool) then
		return true
	else
		return false
	end
end

О, прікол,привіт. I am from Ukraine.

Привет, я тоже из Украины. Привіт я теж з України. Хочешь пойдем в дискорде по переписывемся, если хочешь. I’m from Ukraine too

1 Like

Ок, го мій дс:mpc19801981#6218. Хорошо мой дс:mpc19801981#6218. Good to know brother.