How to add material detection to TurboFusion's gun script?
Basically, it detects what material you're firing at. So, if it's metal, diamond plate, or corroded metal, it changes the bullet hole texture to a dent. I'm having trouble with figuring this out. If someone can help me, thanks!! Also, if you shoot something that's a model, and it has a "Humanoid" in it, it makes a blood splat on that person or creature that was shot, and makes blood splats behind them. I'd like the wound texture to be different from the actual blood splat, as well.
Granite, slate, grass, brick, concrete, cobblestone, and pebbles, plastic, and smooth splastic share the same bullet hole texture. Ice and marble share the same texture. Sand has it's own texture. And metal, corroded metal, and diamond plate share the same same texture. Wood and wooden planks also share the same texture (which are splinters.) Also, if the part is invisible, no bullet holes show up.
--Bullet hole texture script (in the script named "Settings."
4 | BulletHoleVisibleTime = 12 ; |
5 | BulletHoleDisappearTime = 1 ; |
--Part in the gun's main script that creates bullet holes on parts.
01 | function CreateBulletHole(HitPos, HitObj) |
02 | CreateShockwave(HitPos, 0.3 , 0.2 ) |
03 | local SurfaceCF = GetHitSurfaceCFrame(HitPos, HitObj) |
04 | local SurfaceDir = CF(HitObj.CFrame.p, SurfaceCF.p) |
05 | local SurfaceDist = SurfaceDir.lookVector * (HitObj.CFrame.p - SurfaceCF.p).magnitude / 2 |
06 | local SurfaceOffset = HitPos - SurfaceCF.p + SurfaceDist |
07 | local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset |
08 | local HitMark = Instance.new( "Part" ) |
09 | HitMark.BrickColor = BrickColor.new( "Black" ) |
10 | HitMark.Transparency = 1 |
11 | HitMark.Anchored = true |
12 | HitMark.CanCollide = false |
13 | HitMark.FormFactor = "Custom" |
14 | HitMark.Size = VEC 3 ( 1 , 1 , 0.2 ) |
15 | HitMark.TopSurface = 0 |
16 | HitMark.BottomSurface = 0 |
17 | local Mesh = Instance.new( "BlockMesh" ) |
18 | Mesh.Offset = VEC 3 ( 0 , 0 , - 0.05 ) |
19 | Mesh.Scale = VEC 3 (S.BulletHoleSize, S.BulletHoleSize, 0 ) |
21 | local Decal = Instance.new( "Decal" ) |
22 | Decal.Face = Enum.NormalId.Front |
23 | Decal.Texture = S.BulletHoleTexture |
24 | Decal.Parent = HitMark |
25 | HitMark.Parent = Gun_Ignore |
26 | HitMark.CFrame = SurfaceCFrame |
27 | if ( not HitObj.Anchored) then |
28 | local Weld = Instance.new( "Weld" , HitMark) |
31 | Weld.C 0 = HitObj.CFrame:toObjectSpace(SurfaceCFrame) |
32 | HitMark.Anchored = false |
34 | delay(S.BulletHoleVisibleTime, function () |
35 | if S.BulletHoleDisappearTime > 0 then |
38 | if X = = 90 then break end |
39 | if ( not Selected) then break end |
40 | local NewX = X + ( 1.5 / S.BulletHoleDisappearTime) |
41 | X = (NewX > 90 and 90 or NewX) |
43 | Decal.Transparency = NumLerp( 0 , 1 , Alpha) |