Need help making a explosion

What im trying to do is that make a explosion that doesn’t hurt the creator of the explosion, doesn’t hurt teammates, hurts enemies, and flings creator or teammate


			if not hit or not hit.Parent then
			local character = hit.Parent
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if not humanoid or humanoid.Health == 0 then
			local player = plrs:GetPlayerFromCharacter(character)
			if player and (player ~= plr or CheckTeammate(plr,player)) then
			local directionVector = (char.HumanoidRootPart.CFrame.p - Explosion.Position).unit
			local velocity = directionVector * 100
			char.HumanoidRootPart.Velocity = velocity

Just a side note, but Velocity is deprecated in terms of AssemblyLinearVelocity, use that instead

From what I presume to be, did you mean to equal the player (Explosion Target) to the plr (Explosion Owner)? If not, can you address more about the issue in specific where you’re encountering it? Make sure to frequently print() out your variables, and check to see what needs to be debugged or not

1 Like

plr is the creator and player is the player that got hit, but the script just doesn’t work, it kills me still and there is no errors

Remove any normal damage you take from the explosion, you’ll have to create atrificial damage.
Do this by getting the distance from the player and the radius.

local distance = (explosion.Position - character.HumanoidRootPart.Position).magnitude

Now to calculate the damage:

local relativeDistance = (radius - distance)/radius 
-- results in 1 if you are ontop of it
-- results in 0 if you are exactly as far as the radius

Let’s make sure that if the result is negative we dont deal any damage

relativeDistance  = math.max(0, relativeDistance )

Now we make the player take damage

Humanoid:TakeDamage(relativeDistance * 100)