I want to make a script,Thats remove your tools while touch a part/brick,How i do make it,Its for someone i need it to.For whos awansered thanks for helping :)
I'll comment you through the code.
script.Parent.Touched:connect(function(Touch) local Player = game.Players:GetPlayerFromCharacter(Touch.Parent)--Using the Parameter that I named "Touched" to access the Player local Tool = Player.Character:GetChildren()--Gets all the Children that are Inside of the Character local BackPack = Player.Backpack:GetChildren()--Gets All the Children that Are Inside of Player's Backpack for _,v in pairs (Tool) do --This in pairs loop loops through the Character Children if v:IsA("Tool") then--Check if any of the Children are ClassNamed "Tool". v.Parent = Player.Backpack--Parent the Tool to the Player's Backpack. The reason why I parented to the Player's Backpack instead of Destroying it is because when the Player holds the Tool and the tool is removed the Arm stays in the position as if it was still holding the tool. end end for _,v in pairs (BackPack) do--This in pairs loop loops through the Player's Backpack if v:IsA("Tool") then--Check if there Any Object className "Tool" in the backpack v:Destroy()-- if it is then its Destroyed here. end end end)
If you want a further explanation about on of the things I wrote please feel free to comment below! If I helped you solve/answer you problem please accept my answer.
Hmm. Well, in your question, the word 'while' has me confused. Do you want it to remove your tools when you touch the brick, and it never comes back? Or it comes back once you step off the brick? I'll set up both situations.
Never comes back:
script.Parent.Touched:connect(function(hit) if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) for i,v in pairs(Player.Character:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then v:Destroy() end end for i,v in pairs(Player.Backpack:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then v:Destroy() end end end end)
It comes back:
For this one, I recommend making a model Instance inside of the Player, to store all of the tools and HopperBins they had. Then, once they step off the brick, they get their tools back.
script.Parent.Touched:connect(function(hit) if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and not game.Players:GetPlayerFromCharacter(hit.Parent):findFirstChild("Weapons") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) local Model = Instance.new("Model", Player) Model.Name = "Weapons" for i,v in pairs(Player.Character:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then v.Parent = Model end end for i,v in pairs(Player.Backpack:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then v.Parent = Model end end end end) script.Parent.TouchEnded:connect(function(unhit) if unhit.Parent and game.Players:GetPlayerFromCharacter(unhit.Parent) and game.Players:GetPlayerFromCharacter(unhit.Parent):findFirstChild("Weapons") then local Player = game.Players:GetPlayerFromCharacter(unhit.Parent) for i,v in pairs(Player.Weapons:GetChildren()) do v.Parent = Player.Backpack end Player.Weapons:Destroy() end end)