So I'm trying to make bullet holes for my gun. I got the position right, but I can't seem to find the right surface the bullet decal should be on. Right now, it choses the surface based on the mouse. So when there's a wall in between the player and the mouse position and the mouse is pointed at the ground, the decal will be facing upwards, while it shouldn't be, because the bullet never hit the ground, it hit the wall.
So how do I know what is the right position based on a ray coming from the player, to the mouse position? Or is there any other (better) way to do this?
Main problem is at line 31.
Here's the script so far:
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
local Strike = false
local mTarg = mouse.Target
local ray = Ray.new(Tool.Handle.CFrame.p, (mouse.Hit.p - Tool.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, vPlayer.Character, false, true)
local surfaceCF = mouse.Hit
if part and part.Name ~= "BulletHole" and not Strike then --Check if part exist + I don't want any bulletholes to be created on other bulletholes + Strike is wether it hit a humanoid or not, I don't want bulletholes on humanoids
local p = Instance.new("Part")
p.formFactor = "Custom"
p.Size = Vector3.new(0.5,0.5,0.5)
p.Transparency = 1
p.CanCollide = false
p.Locked = true
p.CFrame = part.CFrame + (position - part.Position) --The position of the part is right
p.Name = "BulletHole"
local w = Instance.new("Weld") --So the bulletholes doesn't fall
w.Part0 = mouse.Target
w.Part1 = p
w.C0 = part.CFrame:inverse()
w.C1 = p.CFrame:inverse()
w.Parent = p
local d = Instance.new("Decal")
d.Parent = p
d.Face = mouse.TargetSurface --This is where i don't know what to do
d.Texture = "http://www.roblox.com/asset/?id=64291961"
p.Parent = game.Workspace
delay(5, function()
for i = 1, 100 do
wait()
d.Transparency = d.Transparency + 0.01
end
p:Destroy()
end)
end
Any help is appreciated. C:

3 comments
Trying switching the decal side with if statement (but it takes a lot more space). 'if mouse.TargetSurface == Enum.NormalId.Right then d.Face = Enum.NormalId.Left end' http://wiki.roblox.com/index.php?title=API:Enum/NormalId
hmm, but how do I know when to change the face and when not to? Because when you are shooting to the ground it should be facing up, but when you shoot at a wall you want it to face vertically.
It should be something that checks on what surface the ray hits the part, so I know on what surface I should set the decal.