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

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

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

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)

2 comments

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

0

Also make sure you label each line, that way the reader can understand everything and learn a lot.

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!

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