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.
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.
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)
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.