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."
BulletHoles = true; --This is whether or not bullet holes will appear where you shot BulletHoleTexture = "http://www.roblox.com/asset/?id=190093197"; --This is the texture of the bullet hole BulletHoleSize = 1; --This is how big the bullet hole will be in studs BulletHoleVisibleTime = 12; --This is how long the bullet hole will be visible for BulletHoleDisappearTime = 1; --This is how long it will take for the bullet hole to disappear
--Part in the gun's main script that creates bullet holes on parts.
function CreateBulletHole(HitPos, HitObj) CreateShockwave(HitPos, 0.3, 0.2) local SurfaceCF = GetHitSurfaceCFrame(HitPos, HitObj) local SurfaceDir = CF(HitObj.CFrame.p, SurfaceCF.p) local SurfaceDist = SurfaceDir.lookVector * (HitObj.CFrame.p - SurfaceCF.p).magnitude / 2 local SurfaceOffset = HitPos - SurfaceCF.p + SurfaceDist local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset local HitMark = Instance.new("Part") HitMark.BrickColor = BrickColor.new("Black") HitMark.Transparency = 1 HitMark.Anchored = true HitMark.CanCollide = false HitMark.FormFactor = "Custom" HitMark.Size = VEC3(1, 1, 0.2) HitMark.TopSurface = 0 HitMark.BottomSurface = 0 local Mesh = Instance.new("BlockMesh") Mesh.Offset = VEC3(0, 0, -0.05) Mesh.Scale = VEC3(S.BulletHoleSize, S.BulletHoleSize, 0) Mesh.Parent = HitMark local Decal = Instance.new("Decal") Decal.Face = Enum.NormalId.Front Decal.Texture = S.BulletHoleTexture Decal.Parent = HitMark HitMark.Parent = Gun_Ignore HitMark.CFrame = SurfaceCFrame if (not HitObj.Anchored) then local Weld = Instance.new("Weld", HitMark) Weld.Part0 = HitObj Weld.Part1 = HitMark Weld.C0 = HitObj.CFrame:toObjectSpace(SurfaceCFrame) HitMark.Anchored = false end delay(S.BulletHoleVisibleTime, function() if S.BulletHoleDisappearTime > 0 then local X = 0 while true do if X == 90 then break end if (not Selected) then break end local NewX = X + (1.5 / S.BulletHoleDisappearTime) X = (NewX > 90 and 90 or NewX) local Alpha = X / 90 Decal.Transparency = NumLerp(0, 1, Alpha) RS:wait() end HitMark:Destroy() else HitMark:Destroy() end end) end
To return a material you would use Enumerations.
function getMaterial(part) if part.ClassName=="Part" then return part.Material end end if getMaterial(workspace.Part)==Enum.Material.Plastic then print("Part was plastic") end
This is a very simple detection script for you to use.