Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not ignoring designated part on FindPartOnRayWithIgnoreList()?

Now I have seen other similar questions on various sites, including this one, and I just can't seem to get this to work using the advice from anyone. All I'm trying to do is to get the ray to ignore the part that the ray has created. I have tried simply making the part itself ignored, adding folders, creating tables, etc. Nothing works. Any help is greatly appreciated and I sincerely apologize for asking a question more than once on the site, but I was unable to figure it out using the previous posts. Thank you.

local play = game.Players.LocalPlayer
local mouse = play:GetMouse()
local tool = script.Parent
local equipped = false
local fire = false

function Shoot(pos,laser)
	if fire == true then
	repeat
	wait()
	local folder = workspace.Folder
	local startCFrame  = tool.Handle.CFrame
	local normal = startCFrame.LookVector
	local position = startCFrame.Position
	local ray = Ray.new(position, normal * 500)
	local hit, position, surfaceNormal = workspace:FindPartOnRayWithIgnoreList(ray,{folder}) --problem is here
	laser.Size = Vector3.new(0.4, 0.4, (mouse.Hit.p - tool.Handle.Position).Magnitude)
	laser.CFrame = CFrame.new(tool.Handle.Position:Lerp(mouse.Hit.p, 0.5), mouse.Hit.p)
	until fire == false
	laser:remove()
	end
end

mouse.Button1Up:connect(function()
	fire = false
end)

mouse.Button1Down:connect(function()
	if equipped then
		fire = true
		local laser = Instance.new("Part")
		laser.Name = "Laser"
		laser.TopSurface = Enum.SurfaceType.Smooth
		laser.BottomSurface = Enum.SurfaceType.Smooth
		laser.Size = Vector3.new(0.2, 0.2, 0.2)
		laser.BrickColor = BrickColor.new("Bright red")
		laser.Anchored = true
		laser.CanCollide = false
		laser.Locked = true
		laser.CFrame = tool.Handle.CFrame
		laser.Parent = workspace.Folder
		Shoot(mouse.Hit.p,laser)
	end
end)

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
	fire = false
end)

2 answers

✓ Accepted answer

I answered my own problem. The problem was not FindPartOnRayWithIgnoreList() as the ray is being directed to mouse.Hit.p . Adding a part to the ignore list does nothing, because mouse.Hit.p does not change according to the ray itself. What needed to be done is Mouse.TargetFilter. Adding a folder for all lasers and having the mouse ignore THAT folder each time the laser is fired, fixed the issue.

Here's the complete and working script:

local play = game.Players.LocalPlayer
local mouse = play:GetMouse()
local tool = script.Parent
local equipped = false
local fire = false
local bullet = false

function Shoot(pos,laser)
	if fire == true then
	mouse.TargetFilter = workspace.Folder
	local startCFrame  = tool.Handle.CFrame
	local normal = startCFrame.LookVector
	local position = startCFrame.Position
	local ray = Ray.new(position, normal * 500)
	local hit, position, surfaceNormal = workspace:FindPartOnRay(ray)
	laser.Size = Vector3.new(0.4, 0.4, (mouse.Hit.p - tool.Handle.Position).Magnitude)
	laser.CFrame = CFrame.new(tool.Handle.Position:Lerp(mouse.Hit.p, 0.5), mouse.Hit.p)
	wait()
	laser:remove()
	bullet = false
	end
end

mouse.Button1Up:connect(function()
	fire = false
end)

mouse.Button1Down:connect(function()
	if equipped then
		fire = true
		repeat
		if bullet == false then
			bullet = true
		local laser = Instance.new("Part")
		laser.Name = "Laser"
		laser.TopSurface = Enum.SurfaceType.Smooth
		laser.BottomSurface = Enum.SurfaceType.Smooth
		laser.Size = Vector3.new(0.2, 0.2, 0.2)
		laser.BrickColor = BrickColor.new("Bright red")
		laser.Anchored = true
		laser.CanCollide = false
		laser.Locked = true
		laser.CFrame = tool.Handle.CFrame
		laser.Parent = workspace.Folder
		Shoot(mouse.Hit.p,laser)
		wait()
		end
		until fire == false
	end
end)

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
	fire = false
end)

1 comment

0

Are you sure it wasn't an issue with FindPartsOnRayWithIgnoreList? You were only blocking out the folder, not the parts inside the folder.

When you are excluding things from the ray, they have to be objects and not a string value, number value, etc. They have to be the direct object.

In an array you can include things from workspace.

object list = {game.Workspace.Model, game.Workspace.Part}
workspace:FindPartOnArrayWithIgnoreList(ray, objectList) 

Just make sure you include the EXACT OBJECT and not a name for it.

If you have any questions or issues please contact me. ;)

2 comments

1

I tried this in many forms, I think the issue really comes from the fact that mouse.Hit.p doesn't change, regardless of the ignore list. The mouse is what needs to ignore the list, not the ray itself. Any thoughts on that?

0

The roblox developer site is down right now, which is making this much more difficult.

This discussion is preserved as it was. New answers, comments, and votes are closed.