How to check what tool is equipped from external script?

Hey guys,

How would I go about checking what tool the player has currently equipped from a script that resides outside of the tool itself?

for example

I can access tool attributes from

local tool = script.Parent

if the script is placed within the tool.

How about from a server script within ServerScriptService?

You can check if a tool is equipped by checking if a Child was Added to the player’s character, since when you equip a tool, the tool gets parented to the character. So you can try to make something that handles checking if a child was added to the character and check if was a tool or not via using the parameter of ChildAdded, which is the thing added to something and checking if it was a tool

1 Like

Oh Ok,

something like this?

game.Players.PlayerAdded:Connect(function(plr)
    local player = plr.CharacterAdded:Wait()

    player.ChildAdded:Connect(function(isTool)
        if isTool:IsA("Tool") then
            print("tool added, can save info for later usage..")
        end
    end)
end)

EDITED.

Kinda, but there’s some problems. Firstly, you didn’t specify what plr and you used isTool is the name of the child it found, but you used NewChild. Here’s an example of how you can do it from the server

local players = game.Players

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.ChildAdded:Connect(function(child)
			if child:IsA("Tool") then
				print("Child added was a tool")
			end
		end)
	end)
end)

Ok, Great thank you :slight_smile:

So I take it there is no direct way to access what tool is currently equipped i.e. a function call.

There isn’t a direct way no, you have to check everytiem a child has been added to the character and check if it’s a tool, you can check which tool it is though by checking it’s name, with my example, you can check the name via child.Name and do something accordingly

Ok got, thanks again for you help.

1 Like

Anytime, if you have anymore issues don’t be afraid to maek another post

1 Like