Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix my destroy brick?

i have a brick with a script like this:

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		wait(.1)
		hit.Parent.Humanoid.Health = 0
	else
		hit.Destroy()
	end
end)

but whenever something besides a humanoid touches it it wont destroy it

please help

3 comments

0

Do you want it to be only a player can touch it? Or any object?

0

If your looking to make a script that kills a player then try this

0

FE?

1 answer

✓ Accepted answer

I don't know why your script isn't working, it might be with the way you wrote it. But i rewrote it this way and it works.

function touched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	else
		hit:destroy()
	end
end
script.Parent.Touched:Connect(touched)

4 comments

0

:Remove() is deprecated use :Destroy().

0

it seems to work know Thank you

0

also how can i make a object unremovable?

0

You could maybe use an if statement before destroying the object, if it has a specific property it doesnt destroy.

This discussion is preserved as it was. New answers, comments, and votes are closed.