Possible route to make tools activate through a custom toolbar?

Hello,
I have a custom toolbar, and made a tool equip on landing on a number. My issue is trying to get built-in events, such as Equipped and Activated to work with the tool. Since the default backpack/toolbar is disabled, I figured that these events do not function as intended. If someone could guide me towards that would be stellar.

I appreciate all and any help I receive.

1 Like

Code such as this does not function as it would if the default backpack/toolbar was not disabled.


local t = script.Parent

t.Activated:Connect(function()
	print('lol')
	local h = t.Parent:FindFirstChildOfClass("Humanoid")
	if h and script.Parent.animations:FindFirstChild("idle") then
		print('idle and hum found')
	end
end)

Maybe a way to do it is, to replace the Equipped with checking if the tool is in the character, because when you equip something it actually goes from your backpack to the character.
And a replacment for Activated is, checking if the mous clicked with .Button1Down and also if when it clicked if the tool was equipped, probarly by using a variable.

1 Like

Well those events you use only fire WHEN a player equips, they do not cause a tool to be equipped.

So the way you’d do it is by changing the tool’s parent to the character, instead of the player’s backpack.

Example:

Put this in a button in a GUI:

script.Parent.MouseButton1Click:connect(function()
if script.Parent.Activated.Value == false then
game.Players.LocalPlayer:WaitForChild(“Backpack”):FindFirstChild(tool’s name).Parent = game.Players.LocalPlayer
elseif script.Parent.Activated.Value == true then
game.Players.LocalPlayer.Character:FindFirstChild(tool’s name).Parent = game.Players.LocalPlayer.Backpack
end
end)

Oh, if you don’t know (I’m not sure if you do) how to disable the default toolbar:

Insert this into a LocalScript called “ToolbarDisable” into StarterGui:

game.StarterGui:SetCoreGuiEnabled(“Toolbar”, false)

You can create a custom event for this:

local function GetEquippedEvent()
local event = Instance.new("BindableEvent")
character.DescendantAdded:connect(function(descendant) -- use our own method to detect a tool being equipped, create an event, fire it when conditions are met
       if descendant:IsA("Model") then
       print("tool equipped")
       event:Fire(descendant) -- fire the equipped event and send the tool that was equipped
       end
end)
return event.Event
end

local equippedevent = GetEquippedEvent()

equippedevent:connect(function(tool)
       print(tool.Name.." was equipped")
end)

sorry for the terrible indenting

1 Like

Not sure what decendants do, can I get a link?

yes of course

1 Like

I’ll show an example. So I’m sure you know about parents and children.

Here for example, b is the child of a and a is the parent of b.
But what about c? c isn’t actually a child of a, its a child of b.
So yeah, c is a decendant of a, you can think of it as the child of the child of a.
And also, anything that’s below c would count as a decendant of a as well.

And for .DecendantAdded, this event will fire whenever an object1 is parented to whatever other object2 you used this event on, and it doesn’t matter if object1 was a child or a decendant.

3 Likes