tool.Activated doesn't work when looping through taggs

So, I’m trying to use CollectionService to loop through all tools (instances with the “tool” tag on them) and then do the .Activated event in that “loop”. The first print(tool) does work perfectly fine and it prints out all the different tools. But the print(“tool activated”) doesn’t put anything in the output if you activate a tool.

So, I also used the same methode but with the .Touched event in another script and said event fires perfectly fine. Why does the .Activated event not work? I did check the devforum but I couldn’t find anything. Nothing on the tool documentation aswell.

Here’s the script:

local CS = game:GetService("CollectionService")
local tools = CS:GetTagged("tool")

for i, tool in pairs(tools) do
	
	print(tool)
	
	tool.Activated:Connect(function()
		
		print("tool activated")
		
	end)
end

If the script is loading as soon as the game loads, or you are making it so these tools will operate the same when the player has their tools equipped, this would not work for players who join the game after this script is loaded. Getting the tags as soon as the game loads will only get the tools that are already in the game. In addition, the tools will not have any functions since the connection is only called once (for those who join the game after the load).

You should get the tag and connect the function when the player joins the game. You should also check to see if the tool already has a connection to prevent duplicate function calls.

1 Like

Oh yes, didn’t really think of that when I wrote the script, ty! But still, why is the .Activated event not fired as soon as a tool is activated?

Most of what I’ll say is uncertain, but if your tool doesn’t have a handle, then activate would not work. Maybe you can try disabling RequiresHandle and see if that works

Well, there is a Handle in the tool. The .Activated event also fires in a script directly in the tool itself, so that shouldn’t be the problem

Try putting a wait method on the very top of your code and make it wait for 5 seconds, 10 seconds max. Let me know if it prints anything from there.

It does print what it should and it looks like the script is working now. No idea why… Is it possible that some events of the tools didn’t load yet or something?

It’s like I mentioned before that the tools has not been loaded in yet. Just to reiterate, I suggest you connect them each time the player joins the game so their tools are able to work (or whenever a new tool is added to the game)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.