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

How do i make this script so the ball (ammo) explodes on contact with anything?

This script is inside a turrent.

ball = script.Parent
damage = 50


function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid ~= nil then
		humanoid:TakeDamage(damage)
		ball:Remove()
	end
end
connection = ball.Touched:connect(onTouched)


wait(5)
ball.Parent = nil

1 answer

You can create a new 'Explosion' instance to do just that.

humanoid:TakeDamage(damage)
local explosion = Instance.new("Explosion", ball)
explosion.Position = ball.Position
<Check the ROBLOX wiki, set some properties for it to change the range, damage, etc>
ball:Remove()

Or, you could create your own explosions and explosion API to do so, but this is not needed for a simple script such as this.

http://wiki.roblox.com/index.php?title=API:Class/Explosion

Check that for properties of Explosion!

3 comments

0

Your script did not work. I think you need to tell the script where the explosion will happen...

0

You need to actually parent it to the ball after TakeDamage, or use "Explosion", parentofexplosion instead of "Explosion" in Instance.new

0

Check the edit I posted, it goes in more depth.

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