Giving bulletproof vest health

Ayo was good devforum,

so hear me out folk. I am working on a game and in my game i want to give vests their own health and once it drops below zero or to 0 the vest gets deleted. It already worked however my problem is
im using touched events and when the gun shoots and where the shot lands is called “BulletHit” and inside bullethit it creates a weld to the object wich got shot.

And i want to make the script look if a something got welded onto it and if yes then take off 1 hp of numbervalue

Here is my ServerScript inside the vest.

local VestModel = script.Parent.Parent
local VestItself = script.Parent
local Badge = VestModel.Badge
local BackSign = VestModel.Part
local Middle = VestModel.Middle

local VHealth = script.Parent.VHealth

function ReduceVestHealth(part)
	if part.Name == "BulletHit" then
		VHealth.Value = -1
		
		if VHealth.Value <= 0 then
			VestModel:Destroy()
		end
	end
end

VestItself.Touched:Connect(function(part)
	ReduceVestHealth(part)
end)

Badge.Touched:Connect(function(part)
	ReduceVestHealth(part)
end)

BackSign.Touched:Connect(function(part)
	ReduceVestHealth(part)
end)


Middle.Touched:Connect(function(part)
	ReduceVestHealth(part)
end)

Does this do the trick?

if (part.Name == "BulletHit") and
      (part.nameOfWeld.Part1 == VestModel) then  ...

I’ve seen people in games add a humanoid to the Part that the player interacts with. then subtracting health from the humanoid.

You forgot to make it reduce 1 health from the original health:

function ReduceVestHealth(part)
if part.Name == “BulletHit” then
VHealth.Value = VHealth.Value -1

	if VHealth.Value <= 0 then
		VestModel:Destroy()
	end
end

end

Middle.Touched:Connect(function(part)
ReduceVestHealth(part)
end)

My problem is that "if part.name == “BulletHit” dosent get registered. When you shoot the bullethit gets parented to the players camera and thats in workspace but inside there is the weld wich gets welded to the vest part depending on where it lands. Would that work if i just directly scan for the weld and then keep the function go ?

that explains probaly why it instantly removed the vest when something touched it lol thanks

Would that work giving the vest a humanoid ??

Is your shooting script completely on the Client? If so, when you parent “BulletHit” to the Player’s camera, it would still be on the Client side, as any Camera instance is not replicated across the Client/Server boundary if you have FilteringEnabled set to true. I would suggest using remotes (e.g. RemoteEvents) to overcome this issue. Some developers use complex systems for hit detection. I encourage you to give it a search here on the DevForum because there have been several discussions about how to effectively engineer a hit detection system and what techniques to use.

its not completly client sided. Through remote events others can see it too. Its first created on the client then through remote event it gets replicated to others in their camera i used “FE GunKit” i used a modifeid version of it and modified it again lol

Yes. You can give anything a humanoid as long as it has a part called Head.

wait i just realized something. Could i not where the BulletHit being created in the script can i not just make it that if the part1 weld has the name “Kevlar” fire some certain event wich the script inside the kevlar reacts to via OnServerEvent and then checks if anything got welded to it and if yes then reduce the health ?

I think it’s worth a try. So can I ask the reason you are welding the projectiles to the vest when they hit? Is it just for the visual effect, or what is the purpose of the welding?

the purpose of the weld is because when you shoot i want to create a decal being created to indicate that a shot hit that certain object. If its not welded the decal would be created but then fall through the world lol i forgot the name oh nvm yes the name is “BulletHole” or whatever you call it

https://gyazo.com/e1ab0b01758df0a780edc59a4c2d3f4f

1 Like

i just realized. The bullethit dosent get replicated to others lol oof. Would it work if i use a client script in the vest to check if anything gets welded to it ?

When the bullet hits something, it uses raycasting, and it just creates an anchored part, it is just some kind of welded to it… That means it did not touch it.

I might not be following this correctly and I’m not an expert, but wouldn’t this ensure that BulletHit gets replicated and gets destroyed when the vest is destroyed?


if (part.Name == “BulletHit”) and
(part.Kevlar.Part1 == VestModel) then
part.Parent = VestModel
. . .

I just saw the reply from @AzimuthBecameReal , that might make this reply moot.

Well, it doesn’t fire that function… I’ve tried it in 2 gun kits.

1 Like

guys i just modifed my bullethit creator script and made it so

if EndPos and Hit then
				local SurfaceCF = GetHitSurfaceCFrame(EndPos, Hit)
				local SurfaceDir = CFrame.new(Hit.CFrame.p, SurfaceCF.p)
				local SurfaceDist = SurfaceDir.lookVector * (Hit.CFrame.p - SurfaceCF.p).magnitude / 2
				local SurfaceOffset = EndPos - SurfaceCF.p + SurfaceDist
				local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset
				if (not Hit.Anchored) then
					local Weld = Instance.new("Weld", HitPart)
					Weld.Part0 = Hit
					Weld.Part1 = HitPart
					Weld.C0 = Hit.CFrame:toObjectSpace(SurfaceCFrame)
					HitPart.Anchored = false
				elseif Hit.Anchored then
					HitPart.CFrame = SurfaceCFrame
					HitPart.Anchored = true
				else
					HitPart.Parent = nil
				end
				if HitPart.Name == "PKevlar" or HitPart.Name == "PKevlarBadge" or HitPart.Name == "PKevlarSign" or HitPart.Name == "Middle" then
					local BeingShot = HitPart.Parent.Middle:FindFirstChild("BeingShot")
					BeingShot:FireSever()
				end
			end

however it dosent fire the event BeingShot ???

i just realized my mistage.

First its no HitPart its Hit
Second Because its not hitpart i forgot to change the variable BeingShot

Have you tried Studio’s Breakpoint Replication Beta feature?