Stopping explosion from destroying character joints

A weapon I’m using in my game is destroying the character joints on explosion, which is rather problematic as it can destroy the player’s right arm and make them unable to use any items, plus the items will be destroyed, and they are rather expensive in the game.

Of course this can be stopped by using DestroyJointRadiusPercent and setting it to 0, but the code of the weapon is more complex and I cannot repair it with my programming knowledge. Instead of a local explosion, where I would just need to type explosion.DestroyJointRadiusPercent = 0, the code looks like this instead:

Instance.new("Explosion", workspace).Position = rocket.Position
destroyRocket(rocket)

Is there any way to insert DestroyJointRadiusPercent into this type of script? I’ve been trying to search for help on the forum but I couldn’t find anything, and my attempts of repairing this were just causing errors.

I would really appreciate if someone could help me!

You can turn it into a variable and change properties:

local explosion = Instance.new("Explosion")
explosion.DestroyJointRadiusPercent = 0
explosion.Position = rocket.Position
explosion.Parent = workspace
3 Likes

The explosions are not destroying any character joints now, but the explosions deal no damage, since it was killing the player by breaking the character neck joint. I can repair this problem tho. Thank you!

Actually nevermind, I can’t figure out how to make the explosion deal any damage to the player as well, is there any value which is used to deal damage to the player, or do I have to start with a local?

Okay I figured how to repair the no damage problem, thank you again!

1 Like

Hi, do you mind posting the code on how you were able to make an explosion that doesn’t destroy joints, deal damage? It’s necessary for me to know as well because I want players to be killed by the explosion but i don’t want any parts in the game to break including weapons. Thanks.

1 Like

can you post the code? i need it for my game too

1 Like

I am not fully sure if I correctly remember, but I think it was this script:

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Remote = Tool:WaitForChild("Remote")
local ProjectileScript = Tool:WaitForChild("ProjectileScript")
local HB = game:GetService("RunService").Heartbeat

local AttackAble = true
local AttackReloadTime = 5

function createRocket()
	local rocket = Instance.new("Part")
	rocket.CanCollide = false
	rocket.FormFactor = "Custom"
	rocket.Size = Vector3.new(0.5, 0.5, 1)
	rocket.TopSurface = "Smooth"
	rocket.BottomSurface = "Smooth"
	
	local mesh = Instance.new("SpecialMesh")
	mesh.MeshType = "FileMesh"
	mesh.MeshId = "http://www.roblox.com/asset/?id=189741947"
	mesh.TextureId = "http://www.roblox.com/asset/?id=189741994"
	mesh.Parent = rocket
	
	local bv = Instance.new("BodyVelocity")
	bv.Parent = rocket
	
	local fire = Instance.new("Fire")
	fire.Size = 1
	fire.Heat = 0
	fire.Parent = rocket
	
	local ps = ProjectileScript:Clone()
	ps.Disabled = false
	ps.Parent = rocket
	
	local explodeSound = Instance.new("Sound")
	explodeSound.Name = "ExplodeSound"
	explodeSound.Pitch = math.random(90, 110)/100
	explodeSound.Volume = 0.75
	explodeSound.SoundId = "http://www.roblox.com/asset/?id=83594590"
	explodeSound.Parent = rocket
	
	local thrustSound = Instance.new("Sound")
	thrustSound.Name = "ThrustSound"
	thrustSound.Pitch = math.random(90, 110)/100
	thrustSound.Looped = true
	thrustSound.SoundId = "http://www.roblox.com/asset/?id=12222095"
	thrustSound.Parent = rocket
	
	return rocket
end

function createFakeRocket()
	local fake = createRocket()
	for _, obj in pairs(fake:GetChildren()) do
		if not obj:IsA("SpecialMesh") then
			obj:Destroy()
		end
	end
	return fake
end

function destroyRocket(rocket)
	rocket.ProjectileScript.Disabled = true
	rocket.Anchored = true
	rocket.Transparency = 1
	rocket.Fire.Enabled = false
	rocket.ExplodeSound:Play()
	rocket.ThrustSound:Stop()
	game:GetService("Debris"):AddItem(rocket)
end

function getPlayer()
	return game:GetService("Players"):GetPlayerFromCharacter(Tool.Parent)
end

function lerp(a, b, t)
	return a + (b - a) * t
end

function launchRocket(targetPosition)
	Handle.LaunchSound.Pitch = math.random(90, 110)/100
	Handle.LaunchSound:Play()
	
	local rocket = createRocket()
	local bv = rocket.BodyVelocity
	
	rocket.CFrame = Handle.CFrame * CFrame.new(0, 0.3, -2)
	rocket.Velocity = rocket.CFrame.lookVector
	rocket.Parent = workspace
	rocket.ThrustSound:Play()
	
	local speed = 50
	local a = rocket.CFrame.lookVector * (speed / 2)
	local b = Vector3.new(0, speed, 0)
	local t = 0
	while t < 1 do
		bv.velocity = lerp(a, b, t)
		t = t + HB:wait()
	end
	wait(1)
	
	local ray = Ray.new(rocket.Position, targetPosition - rocket.Position)
	local part, pos = workspace:FindPartOnRay(ray)
	targetPosition = pos
	
	local diveSpeed = 150
	local vector = targetPosition - rocket.Position
	bv.velocity = vector.unit * diveSpeed
	wait(vector.magnitude / diveSpeed)
	
	local explosion = Instance.new("Explosion")
	explosion.Position = rocket.Position
	explosion.DestroyJointRadiusPercent = 0
	explosion.BlastPressure = 1000
	explosion.Parent = workspace
	destroyRocket(rocket)
	
	local MIN_DAMAGE = 15
	local MAX_DAMAGE = 30
	
	explosion.Hit:Connect(function(hit, distance)
    	local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
    	if hum then
        	hum:TakeDamage((1 - distance / explosion.BlastRadius) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
    	end
	end)
	
end

function grabRocket()
	local char = Tool.Parent
	local larm = char:FindFirstChild("Left Arm")
	if larm then
		local fake = createFakeRocket()
		fake.Parent = char
		local weld = Instance.new("Weld")
		weld.Part0 = larm
		weld.Part1 = fake
		weld.C0 = CFrame.new(-0.5, -1, 0) * CFrame.Angles(0, math.pi/2, 0)
		weld.Parent = weld.Part0
		return fake
	end
end

function reloadSequence()
	Remote:FireClient(getPlayer(), "PlayAnimation", "Reload")
	wait(0.25)
	local rocket = grabRocket()
	wait(0.25)
	Handle.ReloadSound.Pitch = math.random(90, 110)/100
	Handle.ReloadSound:Play()
	rocket:Destroy()
end

function activate(targetPosition)
	if not AttackAble then return end
	
	AttackAble = false
	delay(1, function()
		delay(AttackReloadTime, function()
			AttackAble = true
		end)
		for t = 0, AttackReloadTime - 1 do
			delay(t, reloadSequence)
		end
	end)
	
	local spread = 6
	delay(0, function()
		launchRocket(targetPosition)
	end)
	delay(1/5, function()
		launchRocket(targetPosition + Vector3.new(spread, 0, 0))
	end)
	delay(2/5, function()
		launchRocket(targetPosition + Vector3.new(0, 0, spread))
	end)
	delay(3/5, function()
		launchRocket(targetPosition + Vector3.new(-spread, 0, 0))
	end)
	delay(4/5, function()
		launchRocket(targetPosition + Vector3.new(0, 0, -spread))
	end)
end

function onRemote(player, func, ...)
	if player ~= getPlayer() then return end
	
	if func == "Activate" then
		activate(...)
	end
end

Remote.OnServerEvent:connect(onRemote)