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

Explosion for a part isn't working, how do I fix it? [UNSOLVED]

Basically, I need help with a part that's supposed to explode on contact if the part's parent isn't named "Enemy." I've checked the console and no errors are being given. If anyone could help, it'd be much appreciated! It also does a certain amount of damage depending how close you are to the part when it blows up (or when you shoot it, etc.)

The max damage is 75.

local maxDamage = 75



function onTouched(hitPart) 
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 
explosion.BlastRadius = 16
explosion.Hit:connect(function(hitPart, partDistance)

    local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
    if humanoid and hitPart.Parent.Name ~= "Enemy" then
        local distance_factor = partDistance/explosion.BlastRadius
        distance_factor = 1 - distance_factor
		if maxDamage*distance_factor >= 0 then
      	  humanoid:TakeDamage(maxDamage*distance_factor)
		end
    end
end)
explosion.Parent = workspace
end 


connection = script.Parent.Touched:connect(onTouched)



2 comments

0

You forgot a vital piece of information. You told us what you want to happen but you didn't tell us what is really happening.

0

Ah. Nothing is happening. At all. You touch the part and nothing happens.

1 answer

✓ Accepted answer

I was using an explosion earlier today and I forgot one vital thing, which I'm assuming you're forgetting.

Explosions has a property called 'Position'.

Since it's at 0,0,0 on the workspace, you won't see it until you go to the middle of the baseplate.

In order to change the position to a selected part, I would do explosion.Position = part.Position

or

You can put the explosion anywhere using explosion.Position = Vector3.new(0, 0, 0) 0, 0, 0 being where you want the explosion to happen.

3 comments

0

Holy cow. This might just work. If it does, thank you!

0

Hmm, nope. That didn't work.

0

Strange. It should do something since it's in the correct position. It's not at ALL showing up. And there's no errors? And you're testing this in Server Testing?

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