Hello, I was wondering if it was possible to make a script inside of a part that detects forever if the part is touching anything inside of a folder and if it is then it deletes it and sets a bool value called triggered to true for 2 seconds?
(I’m planning to use this script to make a grass cutting thingy)
It would also be great if you could give some examples so i could mark this topic as done
local model = workspace.Model
local part = workspace.Part
local bool = workspace.BoolVal
part.Touched:Connect(function(hit)
for _, v in pairs(model:GetChildren()) do
if hit.Name == v.Name then
part:Destroy()
bool.Value = true
task.wait(2)
bool.Value = false
end
end
end)
This is probably the complete logic you’re looking for.
this makes it so that it destroys the scripts parent ( the grass cutting part ) but i would like it to destroy the part that the scripts parent touches only if its called “grass”, how do i do that?
Well you didn’t ask for that in the original post but:
local model = workspace.Model
local part = workspace.Part
local bool = workspace.BoolVal
part.Touched:Connect(function(hit)
for _, v in pairs(model:GetChildren()) do
if hit.Name == v.Name and hit.Material == Enum.Material.Grass then
part:Destroy()
bool.Value = true
task.wait(2)
bool.Value = false
end
end
end)