What I am trying to achieve is a tool gets removed once the tool touches a specific part. The script below detects if a tool named “Box” touches the part (Restock). I tried using v:remove() but it didn’t work.
local Restock = script.Parent
Restock.Touched:Connect(function(Obj)
if Obj.Parent.Name == "Box" and Obj.Parent:IsA("Tool") then
print("Part Touched")
local PLAYER_OBJECT = Players:GetPlayerFromCharacter(Obj.Parent.Parent)
end
end)
there’s no difference between remove and destroy, the only difference between them is one is deprecated one is not. something that is deprecated still works, however its preferred to use the not deprecated one.
This should work to achieve what you’re looking for:
local restock = script.Parent
restock.Touched:Connect(function(otherPart)
local tool = otherPart:FindFirstAncestorWhichIsA("Tool")
if tool and tool.Name == "Box" then
tool:Destroy()
end
end)
Here’s another method you can use that works basically the same way as JohhnyLegoKing’s one.
local Restock = script.Parent
Restock.Touched:Connect(function(Obj)
if Obj.Parent:FindFirstChildWhichIsA("Tool") then
local Tool = Obj.Parent:FindFirstChildWhichIsA("Tool")
if Tool.Name == "Box" then
print("Part Touched")
Tool:Destroy()
end
end
end)
local Restock = script.Parent
Restock.Touched:Connect(function(Obj)
if Obj.Parent.Name == "Box" and Obj.Parent:IsA("Tool") then
print("Part Touched")
local PLAYER_OBJECT = game.Players:GetPlayerFromCharacter(Obj.Parent.Parent)
Obj.Parent:Destroy()
end
end)
it would most likely be better for the player to use a function where one of the player’s parts touches the part and removes the tool, because if you use a function that detects if a tool has touched it, then it will be a smaller hitbox if you know what i mean ofcourse.