Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

0
That's because the tool must be equipped for the Activate() function to work. Miniller 562 — 2y

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago
Edited 2 years ago

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.

Ad

Answer this question