I have been trying to script a gun. I wanted this gun to have bullet holes, but I have run into a problem. What I believe is happening is that the ray cast is hitting the bullet holes. Watch the video to see the problem. I also have a snippet of my code below. It is not missing an end, I’m just not showing it, all the variables are defined, and this part of the code is a part of a shoot event for the gun. For any more info, just ask me!
local RayCast = Ray.new(FromP, (ToP-FromP).unit*100)
local Part, Position, Normal = game.Workspace:FindPartOnRayWithIgnoreList(RayCast, {plr.Character, tool, game.Workspace.BulletHoles}, false, true)
if Part then
local Hum = Part.Parent:FindFirstChild("Humanoid")
local Dist = (ToP-FromP).magnitude
if Hum and Dist < 300 then
Hum:TakeDamage(7)
end
local Lazer = Instance.new("Part")
Lazer.Parent = game.Workspace
Lazer.Anchored = true
Lazer.CanCollide = false
Lazer.Size = Vector3.new(0.1,0.1,Dist)
Lazer.CFrame = CFrame.new(FromP,Position)*CFrame.new(0,0,-Dist/2)
print(Part.Parent.Name.." WAS SHOT")
if not Part:FindFirstAncestor("BulletHoles") then
local Hole = game.ReplicatedStorage.BulletHole:Clone()
Hole.Parent = game.Workspace.BulletHoles
Hole.Position = ToP
Hole.Name = "BulletHole"
Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
local Weld = Instance.new("Weld")
Weld.Part0 = Part
Weld.Part1 = Hole
Weld.C0 = Part.CFrame:Inverse()
Weld.C1 = Hole.CFrame:Inverse()
Weld.Parent = Hole
game.Debris:AddItem(Hole,5)
end