Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i fix my destroy brick?

Asked by 5 years ago

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

0
Do you want it to be only a player can touch it? Or any object? PoppyandNeivaarecute 134 — 5y
0
If your looking to make a script that kills a player then try this iNykoda 3 — 5y
0
FE? AidanTES 36 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
:Remove() is deprecated use :Destroy(). Rheines 661 — 5y
0
it seems to work know Thank you CubicleHead -3 — 5y
0
also how can i make a object unremovable? CubicleHead -3 — 5y
0
You could maybe use an if statement before destroying the object, if it has a specific property it doesnt destroy. orangebuddycrash 57 — 5y
Ad

Answer this question