Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add material detection to TurboFusion's gun script?

Asked by 10 years ago

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."

1BulletHoles = true; --This is whether or not bullet holes will appear where you shot
2    BulletHoleTexture = "http://www.roblox.com/asset/?id=190093197"; --This is the texture of the bullet hole
3    BulletHoleSize = 1; --This is how big the bullet hole will be in studs
4    BulletHoleVisibleTime = 12; --This is how long the bullet hole will be visible for
5    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.

01function 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 = VEC3(1, 1, 0.2)
15    HitMark.TopSurface = 0
View all 51 lines...

1 answer

Log in to vote
2
Answered by
Dominical 215 Moderation Voter
10 years ago

To return a material you would use Enumerations.

1function getMaterial(part)
2if part.ClassName=="Part" then
3return part.Material
4end
5end
6 
7if getMaterial(workspace.Part)==Enum.Material.Plastic then
8print("Part was plastic")
9end

This is a very simple detection script for you to use.

Read more on Enumerations go to this wiki article

0
Are you 100% sure that'd work, because, honestly, if you look at how my script runs, it wouldn't work. Could you give me a copy of the code I posted with the changes I request? I don't know how to implement that code you posted. TheRings0fSaturn 28 — 10y
Ad

Answer this question