fastslug08
(FastTheDev)
October 26, 2021, 7:24am
#1
Hello i was wondering if it’s possible to make a script inside of a part that only deletes other parts (when touched by the part with the script in it) if their name matches the criteria in the script?
if it is, would it be possible to show me how to do so in the comments?
It is possible,
local specifiedName = "Name"
script.Parent.Touched:Connect(function()
for _, v in pairs (game.Workspace:GetDescendants()) do
if v ~= script.Parent then
if v.Name == specifiedName then
v:Destroy()
end
end
end
end)
2 Likes
fastslug08
(FastTheDev)
October 26, 2021, 7:28am
#3
thanks a lot, ill test this right now.
1 Like
fastslug08
(FastTheDev)
October 26, 2021, 7:30am
#4
for some reason when i tested it, the part deleted all of the other parts with the specified name. do you know why?
1 Like
You said to do nothing or delete? Cause I made it delete the parts with the specified name.
1 Like
fastslug08
(FastTheDev)
October 26, 2021, 7:31am
#6
it deleted all of them, but i wanted it to only delete them when it touches the named parts
1 Like
Alright.
local touchConns = { }
for _, v in pairs (game.Workspace:GetDescendants()) do
if v ~= script.Parent then
if v.Name == specifiedName then
touchConns[#touchConns+1] = v.Touched:Connect(function()
v:Destroy()
end)
end
end
end
Sorry about the formatting
2 Likes
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Name == "" then --some name
hit:Destroy()
end
end)
Code needs to be inside a server script, parent the script to the main part (the one which causes other parts to be deleted).
2 Likes
SuperPogr
(SuperPogr)
October 26, 2021, 7:37am
#9
To remove AnotherPart by simply clicking on the first part.
local Name = game.Workspace.Name
script.parent.clickdetector.mouseclick:Connect(function(player)
Name:Destroy()
end()
The code can be put in the first Part.
2 Likes
The original poster was looking for a script which deletes parts of a specified name if they come into contact with some other part.
4 Likes
They didn’t specify, so I just put in my script if hit.Name == ""
so they can change the name inside the quotes.
3 Likes
fastslug08
(FastTheDev)
October 26, 2021, 10:35am
#13
What do you mean by this, how do i do that?
fastslug08
(FastTheDev)
October 26, 2021, 10:42am
#14
the problem with this one is that even when the player touches the “specified part” it destroys (deletes) , how would i make it so that only the part with the script inside can delete the “specified parts”
Aano_ROBLOX:
Alright.
local touchConns = { }
for _, v in pairs (game.Workspace:GetDescendants()) do
if v ~= script.Parent then
if v.Name == specifiedName then
touchConns[#touchConns+1] = v.Touched:Connect(function()
v:Destroy()
end)
end
end
end
Sorry about the formatting
Just copy and paste the code I provided into a script (not a local script) and then place the script inside the part.
fastslug08
(FastTheDev)
October 26, 2021, 11:24pm
#16
Thanks alot : ) . I hope this works…
Don’t forget that you’ll need to change what’s inside the quotes to match the name of the parts you want this to work on.
2 Likes
fastslug08
(FastTheDev)
October 27, 2021, 1:43am
#18
ok, ill remember that. thanks a lot
fastslug08
(FastTheDev)
October 27, 2021, 1:58am
#19
I did this but it has a very long delay for what i want to use it for…
Aano_ROBLOX:
Alright.
local touchConns = { }
for _, v in pairs (game.Workspace:GetDescendants()) do
if v ~= script.Parent then
if v.Name == specifiedName then
touchConns[#touchConns+1] = v.Touched:Connect(function()
v:Destroy()
end)
end
end
end
Sorry about the formatting
Edit: ill upload the vid somehow: Grasscutting GIF | Gfycat
just to prove that it isn’t lag i set the graphics to the lowest.
is there a way that i can fix the delay?
Can you place all of the parts (all of the grass) inside of a folder? Then place this script inside of the folder.
local Parts = script.Parent:GetChildren()
for I,v in pairs(Parts) do
v.Touched:Connect(function()
v:Destroy()
end)
end
fastslug08
(FastTheDev)
October 27, 2021, 10:19am
#21
But, id like to do it so that only a certain part can “cut” the grass