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

How would I make this Kill script better, if possible?

Asked by 5 years ago

I made this script so when the player jumps on an enemy AI's head the enemy will die. But it doesn't always work.

Such as: When the player jumps and jumps off on the enemy's head the enemy will not die. The player can stand on the enemy's head and it will take a few seconds for the enemy to die.

Is there a possible solution to this?

(Also since I'm a beginner I got some of this code from the Roblox wiki to detect if the thing touching the enemy's head is player and not anything else)

The script is placed inside the enemy's head.

(Explains the - script.Parent(head).Parent(enemy).Humanoid.Health = 0)

local Head = script.Parent

local function handleTouch(otherPart)
  local character = otherPart.Parent
  local humanoid = character:FindFirstChild("Humanoid")
  if humanoid then
    script.Parent.Parent.Humanoid.Health = 0
  end
end

Head.Touched:connect(handleTouch)
0
Change line 11 to :Connect (With a capital C) MexheCo 46 — 5y

Answer this question