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

Is it possible to connect to the Equipped event from a LocalScript in the StarterGui? [closed]

Asked by 9 years ago

I'm working on a script, and I want it to target the equipped tool of the Player who touches a brick The only problem is that I have no idea how I could do this. It can't be a specific tool in the BackPack, because there can be many, but it has to be only the Equipped one. What kind of connection line could I use here?

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You can create an event handler from anywhere, as far as I know. Since the LocalScript is a descendant of Player, we can loop through that player's backpack with a for loop and then create a handler for each tool in the backpack.

local plr = game.Players.LocalPlayer
local backpack = plr:WaitForChild("Backpack")

for i,v in pairs(backpack:GetChildren()) do
    if v.ClassName == "Tool" then
        v.Equipped:connect(function(mouse)
            --stuff
        end)
    end
end

This is what you want, right?

0
Thanks! SlickPwner 534 — 9y
Ad