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

How can you make it so that when you touch a brick it gives you an item?

Asked by 3 years ago

I have been making a game with my little brother and I wanted to make it a survival adventure game. I was trying to make it so that when you touch a blood puddle we put in the game, you get an axe, and I can't. If anyone knows how to do this thank you very much!

2 answers

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

That's easy and by the way scripting helpers.org is not a request site

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        game.ReplicatedStorage.Lemonaid:Clone().Parent = player.Backpack -- Put lemonaid as your axe name

        script.Disabled = true

        wait(2)

        script.Disabled = false
    end
end)
0
Just use a debounce, I wouldn't really recommend using script.Disabled since bugs have happened before, at least with me. That's why debounces exist. :D Nitrolux200 62 — 3y
0
Also make sure you label each line, that way the reader can understand everything and learn a lot. Nitrolux200 62 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Put your tool in ReplicatedStorage, insert a script into the part and type this in. I added a debounce because I suppose it's a multiplayer game so many people that play will get the tool when they reach that part.

db = false -- debounce

local tool = game.ReplicatedStorage.ClassicSword -- change ClassicSword to your tool name

script.Parent.Touched:Connect(function(hit) -- when the part is hit
    if hit.Parent:FindFirstChild("Humanoid")then -- if the part was hit by a humanoid then
        if db == false then -- if debounce is false then
            db = true -- debounce is true
            local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- the player
            local backpack = player:WaitForChild("Backpack") -- player's backpack
            tool:Clone().Parent = backpack -- puts the tool in the player's backpack. Added tool:CLone() before the .Parent = backpack because since many people will get that tool [i suppose] it needs to clone so it doesn't just work once.
            wait(5) -- the delay before you can get the tool again
            db = false -- debounce = false
        end -- ends
    end
end)

Hope this helped! If you want to add indicators like color changes or something like that respond to me and i'll do it for you if you don't know.

Take care!

Answer this question