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

How can I make if player step on a block, the tool from player backpack delete?

So, I got a "small" problem. I can't make if a player step on a block, the tool from the player backpack will destroyed. The "Tool" and the "Area" is located in Workspace, with scripts. The "Tool" is located in Workspace.Tools The "Area" is located in Workspace.Job

I added a script to "Area", and two scripts to the "Tool".

I tried to make some scripts. Here is the script, what I added to the "Area"

Toolname = "TestBox01"

function touch(Player)
	if not Player.Inventory:FindFirstChild("TestBox01") then
		local Box = game.Workspace.Tools.TestBox01:Destroy()
		Box.Parent = Player.Backpack
	end
end

script.Parent.Touched:Connect(touch)

And here is the Tool script.

--PickUpScript

Toolname = "TestBox01"

function touch(Player)
	if not Player.Backpack:FindFirstChild("TestBox01") then
		local Box = game.Workspace.Tools.TestBox01:Clone()
		Box.Parent = Player.Backpack
	end
end

script.Parent.ClickDetector.MouseClick:Connect(touch) 

And another one script in "Tool"

tool = script.Parent
handle = tool:WaitForChild("Handle")

tool.Equipped:Connect(function()
	print("The tool was equipped!")
end)

1 comment

0

You should look in the Output window, you can find it in the View menu. Things like Player.Inventory don't exist as far as I'm aware. I think you're looking for Player.Backpack. Additionally if a part touches something, that other part is generally a part of the character, not the player. Once again the Output should tell most of those things to you.

1 answer

Ok! Here we go, since I was very inactive on this awesome platform and your problem looks kinda easy, I taked the time to make this 'Tutorial' for you!

First Step

Ok! Now, first of all, you need to know how this stuff works correctly. If you want to get the tools from the player you need to use a for loop (it's more asy but not nessesary!). For this we will use the next lines of code!

-- using a localscript right now!

-- locals
local player = game.Players.LocalPlayer
local tools = {}

-- mian script
for _, tool in pairs(player.Backpack:GetChildren()) do

	tools[tool] = tool.Name

end

wait()

print(tools[1]) -- will print the first tool name

Now, we already taked a look of how we can use this for loop to make this type of things! Now, w should try to use this new 'power' to make possible the delete function!

Second Step

Enjoy your programming session! If you're stressed, please take a rest and then come back and try it again! You have to enjoy always what are you dioing! And you have to do it with joy.

We will use the next lines of code to make possible what you want!

local function part_Touched(hit)

	if hit.Parent:WaitForChild('Humanoid') then

		local char = hit,Parent

		if char then

			print('Running script!')

			local player = game.Players:GetPlayerFromCharacter(char) 

			local plrBackpack = player.Backpack

			for _, tool in pairs(plrBackpack:GetChildren()) do

				if tool.Name == 'SpecificToolName' then

					tool:Destroy()

				else

					print("The doesn't exist! Try again when you have it")

				end

			end

		else

			warn('"The character doesn't exist!")

		end

	end

end

-- if you put this script into the touching part this will be ok!
script.Parent.Touched:Connect(function(hit)

	wait()

	part_Touched(hit) -- arguments! never forget them

	print('The part is destoyed! Have a good day!')

end)

Congratulations!

Now you learned how to make this awesome and easy script! You can always contact me on my Discord for more information or more scripts you need! If you need help developing any game, you can contact me too!

Discord: @allgood.#7032

Have a great day!

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