You can write your topic however you want, but you need to answer these questions:
-
I want a ui to open whenever any tool is equipped
-
The issue is, my script doesn’t work (and i don’t know what i am doing wrong)
local GUI = player.PlayerGui
local Backpack = player.Backpack
local tools = Backpack:GetChildren()
tools.Equipped:Connect(function()
GUI.gameplay.Screen.ItemUseFrame.Visible = true
end)
tools.Unequipped:Connect(function()
GUI.gameplay.Screen.ItemUseFrame.Visible = false
end)
Backpack does not have an event for equipping or unequipping a tool.
If you want a global signal for detecting when a tool is equipped, run ChildAdded/Removed on the player’s character and check if it’s a tool.
Player.CharacterAdded:Connect(function(c)
c.ChildAdded:Connect(function(tool)
if tool:IsA("Tool") then
end
end)
c.ChildRemoved:Connect(function(tool)
if not c:FindFirstChildOfClass("Tool") then
-- there is a non-zero chance a player has two tools equipped
-- this is a failsafe that should still work
end
end)
end)
Also, consider enabling the Output Window, it shows Lua errors and tells you whats wrong with your code!
1 Like