Whenever I spray paint they go ontop of eachother

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

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


image


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

Thank you to everyone who has helped!

1 Like

So you would want to cast the ray and then check to see if the part that the ray hit is a “bullet hole”. If it is, then don’t spray. :slight_smile:

1 Like

FindPartOnRayWithIgnoreList()

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)
1 Like

Pass in game.Workspace.PaintFolder as the second argument of FindPartOnRay.
The ray should go through whatever parts are in there.

2 Likes

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
1 Like

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
1 Like

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.

1 Like

This works very well!

image

2 Likes