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?
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)
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)
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.