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

How to make this cannon ball script kill players or NPC's?

What I mean, is how would I make this do 150 damage when it hits a player or a NPC? Also how to make it have a 2/4 chance of breaking that enemies joints if their MaxHealth is less than 1000?

pellet = script.Parent


function onTouched(hit)
	humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid~=nil then
		g = Instance.new("Explosion") 
		g.ExplosionType = Enum.ExplosionType.NoCraters
                g.Parent = game.Workspace 
                g.Position = script.Parent.Position 
                g.BlastRadius = 5
                g.BlastPressure = 1000
                pellet:remove()
	       else
                script.Parent.PelletScript2.Disabled = false
                script.Parent.PelletScript:remove()	
	end
end



connection = pellet.Touched:connect(onTouched)

1 comment

0

If you want it to kill anything, no matter how much health it has, set the damage to inf.

1 answer

✓ Accepted answer

I made it so it does damage, and here is the code:

pellet = script.Parent
damage = 5 -- the damage done.

pellet.Touched:connect(function(hit)
    humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid~=nil then
	humanoid:TakeDamage(damage)
        g = Instance.new("Explosion") 
        g.ExplosionType = Enum.ExplosionType.NoCraters
                g.Parent = game.Workspace 
                g.Position = script.Parent.Position 
                g.BlastRadius = 5
                g.BlastPressure = 1000
                pellet:remove()
           else
                script.Parent.PelletScript2.Disabled = false
                script.Parent.PelletScript:remove() 
end
end)

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