Touch brick = new item

I am super sorry about the title. I had no idea how to explain it very very briefly. I am trying to make something where if you touch a certain brick, it adds an item to your starterpack. I have no idea how to do it. This is for my roblox airline. Thanks!

Note: I am NOT implying in the above statements that I want you to write a script for me. I simply want you to tell me if there are any dev hub posts, youtube videos, etc for me that would help me in this situation. If you want to write a script for me I don’t mind. But I am not asking for it.

You need to have the reference to the tool you want to add to the player.
You can use the .Touched event, then clone the tool and parent it to the Player.Backpack.

For example:

local Tool = ReplicatedStorage.Tool -- this is just the tool you want to add to your backpack
local Brick = game.Workspace.Part -- this is the brick that adds the tool when touched.

Brick.Touched:Connect(function(other)
     -- Check if the other part is part of a player
    if other.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(other.Parent)
        local tool = Tool:Clone()
        tool.Parent = player.Backpack
    end
end)

You would need to add a check to see whether the player already has the tool, and also add debouncing so that the tool doesn’t get cloned a huge number of times.

How do I add the check part and the debounce?

Modifying my code from earlier:

local Tool = ReplicatedStorage.Tool -- this is just the tool you want to add to your backpack
local Brick = game.Workspace.Part -- this is the brick that adds the tool when touched.

local debounce = false

Brick.Touched:Connect(function(other)
    if debounce then return end
     -- Check if the other part is part of a player
    if other.Parent:FindFirstChild("Humanoid") then
        debounce = true

        local player = game.Players:GetPlayerFromCharacter(other.Parent)

        -- If there is a tool with the same name in the backpack already, then return
        if player.Backpack:FindFirstChild(Tool.Name) then return end

        local tool = Tool:Clone()
        tool.Parent = player.Backpack

        debounce = false
    end
end)

The debounce variable makes the function binded to .Touched only run once at a time, meaning that the function only runs if it isn’t running already.

Hope this helps :smiley:

Last question: Where do I put this script and what kind of script?

It would be a server script and should be somewhere on the server, such as workspace.