Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

0

It doesn't work, it only clones the tools and it doesn't equip.

0

do you have any errors in the output panel

This discussion is preserved as it was. New answers, comments, and votes are closed.