How to use a tool to delete a certain part?

I want to make a sledgehammer that deletes itself after it breaks a certain part, which is a door. No errors, or anything but yet it still doesn’t work.

It doesn’t delete the part I want, no errors, it just doesn’t delete the part.

My script was fairly simple, doing this:

local tool = script.Parent

local event = tool.OnActivated

event.OnServerEvent:Connect(function(hit)
	if hit.Parent:IsA("Part") and hit.Parent.Name == "StoneDoor" then
		hit.Parent:Destroy()
		tool:Destroy()
	elseif hit.Parent.Name ~= "StoneDoor" then
		print("not the target")
	end
end)

Is there an alternative to finding that certain part?

2 Likes

your hit variable is the player, instead just do (plr,hit)

1 Like

I’m trying to delete a certain part. not a player.

Also it didn’t work… Same exact thing happened

What I’m trying to say is,

Your hit is instead of the information you want to send, its actually the player. It’s because of how it is.

ooohhh ok.

Any other way I get get the part instead of getting its name?

You could make a table:

local tool = script.Parent

local event = tool.OnActivated

local listedBreakable = {
    "StoneDoor"
}

event.OnServerEvent:Connect(function(plr, hit)
	if hit.Parent:IsA("Part") and table.find(listedBreakable, hit.Name) then
		hit.Parent:Destroy()
		tool:Destroy()
	else
		print("not the target")
	end
end)
1 Like
local tool = script.Parent
local handle = tool.Handle

tool.Activated:Connect(function()
	handle.Touched:Connect(function(hit)
		if hit.Name == "StoneDoor" then
			hit:Destroy()
			tool:Destroy()
		elseif hit.Name ~= "StoneDoor" then
			print("not the target")
		end
	end)
end)

He probably would want to put the touched thing in a server.

Also, for animation purposes. characters i need are 30

That script would work as a server script. I just got rid of the OnServerEvent stuff and used the tool’s “Activated” event instead.

its a singleplayer game. So it doesnt matter if its serversided or clientsided

Okay, but the devforum wont allow me to reply or post without putting 3 x 10 characters in.

I recommend using client server stuff to do animation. Well, if you want.

I wont need it yet cuz its a learning experience at the same time. horror/learning experience

Ok, but the devforum wont allow me to reply or post without putting 3 x 10 characters in. Also it needs to be different.

local tool = script.Parent
local handle = tool.Handle

tool.Activated:Connect(function()
	handle.Touched:Connect(function(hit)
		if hit:FindFirstAncestor("StoneDoor") then
			hit:FindFirstAncestor("StoneDoor"):Destroy()
			tool:Destroy()
		end
	end)
end)

If “StoneDoor” is a model then this will need to be used instead.

Its a part, not a model.

gotta add more characters in order to reply!!!

Okay, then the other script I provided would work.

It didnt work for some reason, no errors at all.

https://gyazo.com/e8ddea1ed66fe6144ae33e5613fbc7b6

image

image

It does work.