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

How do i just kill zombies with part.Touched, not my character or other players?

Asked by 5 years ago
Edited 5 years ago

I was going to do this script just to kill the zombies, but when I touch the part, I die. How do I make sure that both me and other players don't die when they get into it?

part.Touched:Connect(function(p)
    if p.Parent:FindFirstChildOfClass("Humanoid") then

        local plr = workspace[p.Parent.Name]

        wait(1)
            plr.Humanoid.Health = plr.Humanoid.Health - 20
        wait(0.1)
        part:Destroy()

    end  

end)
0
I would rename the zombies humanoids to "Zombie" then replace the "p.Parent:FindFirstChildOfClass("Humanoid")" to p.Parent:FindFirstChildOfClass("Zombie") (this is how my weapons work, to prevent team killing), tell me if you need a better explanation of it  LoganboyInCO 150 — 5y
0
Nah it doesnt work :C. I Just did a weapon when you activate it, it create new part front of the player and it will be damage all things just not players. But i cant do it aSpecialGuy 18 — 5y

1 answer

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

You can rename zombie humanoid to "Zombie" and find the Humanoid by it's name.

Here's the code:

part = script.Parent
debounce = false
part.Touched:Connect(function(p)
if debounce == true then --check for cooldown
debounce = false --cooldown on
        local hum = p.Parent:FindFirstChildOfClass("Humanoid") --find humanoid from the touched event
        if hum.Name == "Zombie" then --check if humanoid name is a zombie
        hum:TakeDamage(20)
        wait(1) --interval
debounce = true --cooldown off
       -- part:Destroy()

       end 
    end)
0
Also recommended to add cooldown for your script so it will active only once, or in an interval. zuup123 99 — 5y
0
Yes everything worked im not dying and players too but now, i just want to give once 20 damage but i cant do it i tried to add wait things but doesnt work again can you tell me what i have to do for it ? aSpecialGuy 18 — 5y
0
I've edit my answer so you can see how to make cooldown zuup123 99 — 5y
Ad

Answer this question