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)
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!
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!
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)
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!