RB-004
Roblox give tool on touch script
A part that gives the player a tool from ServerStorage when they touch it.
- Script type
- Script
- Where it goes
- Inside the Part
- Category
- Doors and interaction
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Give tool on touch: copies a Tool from ServerStorage into the player's Backpack.
local TOOL_NAME = "Sword" -- the name of a Tool inside ServerStorage
local COOLDOWN = 2 -- seconds before the same player can be checked again
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local part = script.Parent
local tool = ServerStorage:WaitForChild(TOOL_NAME)
local busy = {}
local function playerHasTool(player)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack and backpack:FindFirstChild(TOOL_NAME) then
return true
end
local character = player.Character
if character and character:FindFirstChild(TOOL_NAME) then
return true
end
return false
end
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player or busy[player] then
return
end
busy[player] = true
if not playerHasTool(player) then
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
tool:Clone().Parent = backpack
end
end
task.wait(COOLDOWN)
busy[player] = nil
end)How to set it up
- Make or insert a Tool (Explorer, plus button, Tool). Give it a Part named Handle.
- Drag the Tool into ServerStorage and rename it Sword (or any name you like).
- Insert a Part, add a Script to it, and paste the code. Set TOOL_NAME to your tool name.
- Play and touch the part. The tool appears in your hotbar.
Change it
- The tool is lost when the player dies, because the Backpack is reset. Use a StarterPack copy if you want it to stay.
- The script checks if the player already has the tool, so they do not collect 50 swords.
- The tool must be a Tool object with a Handle, or it cannot be held.
More in Doors and interaction
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.