Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do i fix my destroy brick?

Asked by 2 months 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 22 — 2mo
0
If your looking to make a script that kills a player then try this iNykoda 1 — 2mo
0
FE? AidanTES -11 — 2mo

1 answer

Log in to vote
0
Answered by 2 months ago
Edited 2 months 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 582 — 2mo
0
it seems to work know Thank you CubicleHead -1 — 2mo
0
also how can i make a object unremovable? CubicleHead -1 — 2mo
0
You could maybe use an if statement before destroying the object, if it has a specific property it doesnt destroy. orangebuddycrash 57 — 2mo
Ad

Answer this question