#Tool Equipped and Unequipped

1 messages · Page 1 of 1 (latest)

urban oasis
#

I'm pretty new to Lua and Roblox Studio, so with my current knowledge I wrote this code that is supposed to detect if a tool is equipped or unequipped by the player. I have two scripts, one under the tool which works fine:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local prompt = game.Workspace.Testpart.ProximityPrompt
local equiped = false

tool.Equipped:Connect(function()
print("Equipped")
equiped = true
end)

tool.Unequipped:Connect(function()
print("Unequipped")
equiped = false
end)

prompt.Triggered:Connect(function(player)
if equiped == true then
print("Active")
elseif equiped == false then
print("Inactive")
end

end)

And another one under the proximity prompt which doesn't detect if the tool is equipped or not:

local prompt = script.Parent
local equiped = false
local players = game.Players
local backpack = nil
local tool = nil

players.PlayerAdded:Connect(function(player)
backpack = player.Backpack
tool = backpack.Tool
print("Player added")
tool.Equipped:Connect(function()
print("Equipped2")
equiped = true
end)
tool.Unequipped:Connect(function()
print("Unequipped2")
equiped = false
end)
end)

prompt.Triggered:Connect(function(player)
if equiped == true then
print("Active2")
end
if equiped == false then
print("Inactive2")
end
end)

Any help is appreciated, thanks!

dusty jungle
#

because the tool is per character, so once the character resets it wont work anymore

#

you want to set it to use character added

#

You could also do something like this

local prompt = script.Parent
local equiped = false
local players = game.Players
local backpack = nil
local tool = nil

players.PlayerAdded:Connect(function(player)
    local Backpack: Backpack = player.Backpack
    Backpack.ChildAdded:Connect(function(child)
        tool.Equipped:Connect(function()
            print("Equipped2")
            equiped = true
        end)
        tool.Unequipped:Connect(function()
            print("Unequipped2")
            equiped = false
        end)
    end)

end)

prompt.Triggered:Connect(function(player)
    if equiped == true then
        print("Active2")
    end
    if equiped == false then
        print("Inactive2")
    end
end)```
#

I dont really get the use of this script tho

crisp copper
#

via ```

urban oasis