Hey there, I made gun that is marking where the bullet was hitted by wall etc. it works well but for one small problem, when I shoot twice on same direction the 2th raycast will detect bullet so it is going to make hole mark in air and I don’t want that here is my script:
Bullet.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") and hit.Name ~= "Handle" and hit.Name ~= "Bullet" then
Bullet:Destroy()
local bulletHole = Instance.new("Part",workspace)
bulletHole.Name = "Hole"
bulletHole.CFrame = CFrame.new(result.Position,result.Position + result.Normal)
bulletHole.Size = Vector3.new(0.35, 0.35, 0.05)
bulletHole.Transparency = 1
bulletHole.CanCollide = false
local image = Instance.new("Decal",bulletHole)
image.Texture = "http://www.roblox.com/asset/?id=2078626"
image.Face = "Front"
end
end)
If anybody know how could I pretend happening please comment down below!
Hmm. First off, when making projectiles it’s commonly known that Raycasting is more reliable then the Touched event. While it does seem like your code utilizes Raycasting, it only seems to do so to position the bullet hole. Because your code uses the touched event the only advice I can give you is to use the new BasePart | Roblox Creator Documentation property to disable the bullets being able to fire this event.
That feature is not out yet however, so if you want to make it work right now then you can do some Raycasting utilizing RaycastParams | Roblox Creator Documentation. Raycasting parameters can help you filter out parts you don’t want to hit. Basically you raycast and update the bullets position each loop iteration and if the raycast returns a result then you break the loop, destroy the bullet, and use the result to position the bullet hole.
Make a table named “IgnoreList”, make a for loop that detects the entire workspace for transparent parts then add them in to the IgnoreList. When a bullet hole is formed/spawned/cloned, you can go ahead and insert the bullet hole into the IgnoreList, make sure you set IgnoreList to blacklist. You can also add a folder in the workspace named “Debris”, this way every bullet hole/debris will be stored in the folder can be ignored.
local IgnoreList = {}
local TransparentParts = {}
for _,v in pairs(TransparentParts) do
table.insert(IgnoreList,v)
end
for _,v in pairs(workspace.Debris:GetChildren())do
table.insert(IgnoreList,v)
end
for _,part in pairs(workspace:GetDescendants())do
if part:IsA("BasePart") then
if part.Parent == workspace.Debris then
table.insert(IgnoreList,part)
end
if part.Transparency > 0.95 then
table.insert(TransparentParts,part)
end
end
end