I want a script which detects if a tool is equiped but so far I didn't find anything. Here is a script which I found here but didnt work:
local player = game.Players.LocalPlayer local character = player.Character local tool = character:FindFirstChildWhichIsA("BackpackItem") if tool then print('equiped') else print('unequped') end
So you probably have not heard of events. Events are basically where roblox listens into specific events, such as seeing if the tool is equipped or unequipped. There is specific events depending on the context. Also you can put your script under the tool instead of where you putted it.
script.Parent.Equipped:Connect(function() end)
So when a player equips the tool, the event will fire and will run any code inside it. Also script.Parent
is the same as game.Workspace.Tool
. Another event you should notice is the unequipped event.
script.Parent.Unequipped:Connect(function() end)
You can either connect a named function or use an anonymous function (which I currently used.) You can find more information in the wiki about how to use events right here. So I'll change the script to what you wanted.
script.Parent.Equipped:Connect(function() print("Equipped") end) script.Parent.Unequipped:Connect(function() print("Unequipped") end)
tool.Equipped(function() is a simple way to print/execute a script when the player equips the tool , noos
--fla
character.ChildAdded:Connect(function(obj) if obj:IsA("Tool") then print(obj.Name) end end)
Easily just use
script.Parent.Equipped:Connect(function() print("Equipped") end)