I am working on a script to place and replace a tool using ClickDetectors, but I do not know how to script a code to destroy certain tools in a player’s inventory on click. Here is my code right now:
place = script.Parent
visible = place.visible
block = game.ServerStorage:WaitForChild'Block'
blockCheck = nil
active = false
place.Block.Part.Touched:Connect(function(part)
if not active then
active = true
blockCheck = part.Parent:FindFirstChild("Block")
if not visible.Value and blockCheck then
for i,v in pairs(place.Block:GetChildren()) do
v.Transparency = 0
end
blockCheck:Destroy()
visible.Value = true
end
wait(.2)
active = false
end
end)
place.Block.Part.ClickDetector.MouseClick:Connect(function(player)
if not active then
active = true
if visible.Value then
for i,v in pairs(place.Block:GetChildren()) do
v.Transparency = 0.8
end
local newBlock = block:Clone()
newBlock.Parent = player.Backpack
player.Character.Humanoid:EquipTool(newBlock)
visible.Value = false
end
wait(.2)
active = false
end
end)
Are there any ways to replace the first paragraph with the Touched function with a ClickDetector function without ruining the second part of the script? Can give setup screenshots in needed.