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

How to make all tools activated by left mouse-click at once (script)?

I am struggling to activate all my tools by mouse clicking it but only 1 tool worked while I'm equipping many tools at once. This is my script to activate all tools but it need to be executed in the executor:

for i,v in pairs(game:GetService("Players").LocalPlayer.Backpack:GetChildren())do
if v.ClassName == "Tool" then
v.Parent = game:GetService("Players").LocalPlayer.Character
end
end
for i,v in pairs(game:GetService("Players").LocalPlayer.Character:GetChildren())do
if v.ClassName == "Tool" then
v:Activate()
end
end

1 comment

0

That's because the tool must be equipped for the Activate() function to work.

1 answer

There's a few things that you need to do to make this work

First of all, use the function Humanoid.EquipTool instead of setting the tool's parent.

Second, you should only use one loop instead of 2. If you want to activate every single tool, you can just unequip (Humanoid.UnequipTools()) the current tool before looping through them.

And finally, use wait() between equipping and activating, and also before equipping a new tool.

local player = game.Players.LocalPlayer
player.Character.Humanoid:UnequipTools()
for i,v in pairs(player.Backpack:GetChildren())do
	if v:IsA("Tool") then
		player.Character.Humanoid:EquipTool(v)
		wait()
		v:Activate()
	end
	wait()
end

If you want to know more check out the devhub.

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