What do you want to achieve? Keep it simple and clear!
I wan’t to make a spray paint game. To spray the paint it uses the same method of making bullet holes with a raycast.
What is the issue? Include screenshots / videos if possible!
It works, but every time I spray paint the paint ( Or bullet holes however you call em) go ontop of eachother.
What solutions have you tried so far?
I’ve tried going on the dev hub and looking around but I couldn’t make anything work or find anything that works. Using TargetFilter would only do one-part so I couldn’t do that, I also tried checking if the target is a bullet hole and if it is not to draw but it is snappy and not how I want. I also tried :FindPartOnRayWithIgnoreList() but I really didn’t understand that.
Heres the code: (Theres other code but this is the important one)
function shoot()
local ray = Ray.new(Arms.CanRig.con.CFrame.p, (Mouse.Hit.p - Arms.CanRig.con.CFrame.p).unit*300)
local hit, pos, normal = game.Workspace:FindPartOnRay(ray)
-- If I hit a wall, then
local bullethole = bulletholepart:Clone()
bullethole.Parent = game.Workspace.PaintFolder
bullethole.CFrame = CFrame.new(pos, pos + normal) -- the most important part: this sets the CFrame of the bullethole so that it's nearly flush with the wall.
end
That function is the same as FindPartOnRay but it ignores the things inside a table you specify, you can make a table with all the bulletHoles added.
(You can use the parameters you did before normally.)
local ignoreList = {}
-- After doing bullethole..
table.insert(ignoreList, bulletHole)
workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
--If you are going to delete the bullet hole do this before deleting..
local indexOfHole = table.find(ignoreList, bulletHole)
table.remove(ignoreList, indexOfHole)
Hey, thank you! I think this is what I need, but is this how I incorporate the script?
local hit, pos, normal = game.Workspace:FindPartOnRay(ray)
-- If I hit a wall, then
local bullethole = bulletholepart:Clone()
bullethole.Parent = game.Workspace.PaintFolder
bullethole.CFrame = CFrame.new(pos, pos + normal) -- the most important part: this sets the CFrame of the bullethole so that it's nearly flush with the wall.
table.insert(ignoreList, bullethole)
workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
end
Creating a whole new table to store the bullethole textures is redundant. The second argument of FindPartOnRay takes an instance of objects that are to be ignored. You are already placing the texture parts inside their own folder, so just use that.
function shoot()
local ray = Ray.new(Arms.CanRig.con.CFrame.p, (Mouse.Hit.p - Arms.CanRig.con.CFrame.p).unit*300)
local hit, pos, normal = game.Workspace:FindPartOnRay(ray, workspace.PaintFolder) -- just need this
-- If I hit a wall, then
local bullethole = bulletholepart:Clone()
bullethole.Parent = game.Workspace.PaintFolder
bullethole.CFrame = CFrame.new(pos, pos + normal) -- the most important part: this sets the CFrame of the bullethole so that it's nearly flush with the wall.
end
I agree with @Blokav. There is no point of using an ignore list if you don’t want your bullet holes to overlap. Simply check to see if the current part that your ray hit is not another bullet hole part.