PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Non lethal explosions

Non lethal explosions

Oct 01 2018, 2:29 AM PST

This sample includes an example of how Explosions can be made non lethal to player characters.

-- listen for new Explosion's being added to the workspace
workspace.DescendantAdded:Connect(function(instance)
	if instance:IsA("Explosion") then
		local explosion = instance
		-- set DestroyJointRadiusPercent to 0
		explosion.DestroyJointRadiusPercent = 0
		-- implement our own DestroyJointRadiusPercent
		local destroyJointRadiusPercent = 1
		explosion.Hit:Connect(function(part, distance)
			-- check the part is in range to break joints
			if distance <= destroyJointRadiusPercent * explosion.BlastRadius then
				-- make sure the part does not belong to a character
				if not game.Players:GetPlayerFromCharacter(part.Parent) then
					-- break joints
					part:BreakJoints()
				end
			end
		end)
	end
end)