How can I make when a player touches a part it removes all of their tools
Use the .Touched event. Then from there get the player from the character that touched. You’d then be able to destroy all the descendants of backpack
ok
Let me know if you have anymore questions!
i wrote a script and it does not work can you help me
Sure, let me know what’s wrong and send the script too
This must be a normal script that is a child of the part
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for i, v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local tool = player.Character:FindFirstChildWhichIsA("Tool")
if tool then tool:Destroy() end
end
end)
in the part
local Part = script.Parent
Part.Touched:Connect(function(Hit)
local p = game.Players:GetPlayerFromCharacter(Hit.Parent) -- gets player from character
if p then p.Backpack:ClearAllChildren() end -- remove tools
end
wait nvm my scriptworks now
local door = script.Parent
local function remove(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if humanoid and player then
local inHand = otherPart.Parent:FindFirstChildWhichIsA('Tool')
local inBackpack = player.Backpack:FindFirstChildWhichIsA('Tool')
if inHand then
inHand:Destroy()
end
if inBackpack then
inBackpack:Destroy()
end
end
end
door.Touched:Connect(remove)