Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if the player has a tool equiped?

Asked by 4 years ago

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
0
Confusing, very confusing for me... LittleGabieleRob 5 — 4y
0
Maybe you could use Tool.Equipped? holamii2 45 — 4y
0
player.CharacterAdded:Wait() PrismaticFruits 842 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago

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)
0
I tried this method but id didn’t work. I basicly want the players arm to move to a specific spot (Torso.Motor6D.CurrentAngle = 1) but with this method when I equip teh tool it moves to that spot but when I unequip it and want to go back to its prevoius state (CurrentAngle = 0) it wont. So now Im trying to make a script which detects if a tool is equiped and then move the arm. Hyperpublic 4 — 4y
0
According to this wiki: https://developer.roblox.com/en-us/api-reference/property/Motor/CurrentAngle it has to be in radians, not degrees. So use math.rad() to accomplish it, and also check the original torso position. Dovydas1118 1495 — 4y
Ad
Log in to vote
0
Answered by
OFF_S4LE 127
4 years ago

tool.Equipped(function() is a simple way to print/execute a script when the player equips the tool , noos

--fla

Log in to vote
0
Answered by 4 years ago
character.ChildAdded:Connect(function(obj)
    if obj:IsA("Tool") then
        print(obj.Name)
    end
end)
0
There's a thing called Player.Backpack. You don't need the character. Dovydas1118 1495 — 4y
Log in to vote
0
Answered by 4 years ago

Easily just use

script.Parent.Equipped:Connect(function()
    print("Equipped")
end)

Answer this question