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

How do I make a Tool stolen by the player who touches it?

Asked by 5 years ago

Let's say Player 1 is holding a tool and Player 2 touches the tool. How do I remove the tool from the Player 1's inventory and move it into Player 2's inventory and have them automatically hold it?

1 answer

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
5 years ago
Edited 5 years ago

Server script in the tool

local Players = game:GetService("Players")
local Tool = script.Parent

for Index, Descendant in pairs(Tool:GetDescendants()) do
    if Descendant:IsA("BasePart") then
        Descendant.Touched:Connect(function(HitPart)
            local Character = HitPart.Parent
            local Player = Players:GetPlayerFromCharacter(Character)
            if Player then
                local Backpack = Player:WaitForChild("Backpack")
                local Humanoid = Character:WaitForChild("Humanoid")
                Tool.Parent = Backpack
                Humanoid:UnequipTools()
                Humanoid:EquipTool(Tool)
            end
        end)
    end
end
0
It doesn't work, it only clones the tools and it doesn't equip. kenappleby -8 — 5y
0
do you have any errors in the output panel Griffi0n 315 — 5y
Ad

Answer this question