โ† Back to all scripts

Give Tool on Touch

Give a player a tool from ServerStorage when they step on a part.

ToolsBeginnerScript inside Part
give-tool-on-touch.lua
-- Give Tool on Touch
local ServerStorage = game:GetService("ServerStorage")
local TOOL_NAME = "Sword"
local debounces = {}

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not player or debounces[player.UserId] then return end
    debounces[player.UserId] = true
    local tool = ServerStorage:FindFirstChild(TOOL_NAME)
    if tool and not player.Backpack:FindFirstChild(TOOL_NAME)
       and not hit.Parent:FindFirstChild(TOOL_NAME) then
        tool:Clone().Parent = player.Backpack
    end
    task.wait(1)
    debounces[player.UserId] = nil
end)
Something broken or not working?
๐Ÿ”ง Try the AI Script Fixer โ†’