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

How do you make a weapon go to your backpack when equipped?

Asked by 5 years ago

Heres the equip script:

local equipped = script.Parent.Parent.Parent.Handler.Equipped
local selected = script.Parent.Parent.Parent.Handler.Selected
local location = script.Parent.Parent.Parent.Handler.Location
local player = game.Players.LocalPlayer
local character = player.Character

script.Parent.MouseButton1Click:connect(function()
    if equipped.Value == nil or equipped.Value ~= selected.Value then 
        character.Humanoid:UnequipTools()
        if location.Value == player.Backpack then
            character.Humanoid:EquipTool(selected.Value)
            equipped.Value = selected.Value
            script.Parent.Text = "Unequip"
        end
    else
        character.Humanoid:UnequipTools()
        equipped.Value = nil
        script.Parent.Text = "Equip"
    end
end)
0
When you equip a tool it gets parented to your character. If you parent it back to the back it will be unequipped. A tool cant be in backpack and equipped at the same time. Amiaa16 3227 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I managed to get a tool to equip. All you need to do is clone the tool into the players backpack. Hope This Helps

function onTouch(part) 
    local plr = game.Players:GetPlayerFromCharacter(part.Parent) 
    local wplr = part.Parent

    wplr.Humanoid:EquipTool(plr.Backpack.Tool)
end
script.Parent.Touched:connect(onTouch)
0
would i put this in the above script or in a separate script? ChefDevRBLX 90 — 5y
0
Above DuckyRobIox 280 — 5y
0
i tried it and it lets me equip it once but when i unequip i cant equip it again. ChefDevRBLX 90 — 5y
0
Try Seperate DuckyRobIox 280 — 5y
View all comments (3 more)
0
Ok ChefDevRBLX 90 — 5y
0
Use :Connect instead of :connect. :connect is deprecated. oilsauce 196 — 5y
0
Also, this is really inconvenient since this is just assuming that the character is the only thing that will touch the tool, and will cause an error if something else that doesn't have a player or a Humanoid touches the tool. oilsauce 196 — 5y
Ad

Answer this question