I need help with this script I made (I’m new to scripting). I’m trying to make the script (the script is in a tool) destroy a part if it’s named Stone but it’s just destroying any part regardless of it’s name.
script.Parent.Handle.Touched:Connect(function(hit)
if hit:FindFirstChild("Humanoid") == nil then
if hit ~= nil then
hit.Touched:Connect(game.Workspace.Stone)
hit:Destroy()
end
end
end)
script.Parent.Handle.Touched:Connect(function(hit)
if hit:FindFirstChild("Humanoid") == nil then
if hit ~= nil then
if hit.name = ("Stone") then
hit:Destroy()
end
end
end
end)
You don’t need to connect it just like you did on line 4. All you need to do is to check if the Hit exists and if it has a Parent, If so, We can just check it’s name and then Destroy it.
script.Parent.Handle.Touched:Connect(function(Hit)
if Hit and Hit.Parent then
if Hit.Name == "Stone" then
Hit:Destroy()
Hit = nil
end
end
end)