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

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

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?

1 answer

✓ Accepted answer

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?

1 comment

0

Thanks!

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