Hey guys, I have been working on a gun, and all seems well until the ray looks for a part to hit. Despite being told to ignore player.Character, hitPart.Name still prints Y35X (my username) Here is the code that I am using.
local ray = Ray.new(tool.Hole.CFrame.p, (mouse.Hit.p - tool.Hole.CFrame.p).unit * configurations.Range.Value)
local hitPart, position = workspace:FindPartOnRay(ray, player.Character, false, true)
the ray is being shot from a point on my pistol, nowhere near any body part, which makes me think that it is hitting a part of the gun, so I changed the script to this:
local ray = Ray.new(tool.Hole.CFrame.p, (mouse.Hit.p - tool.Hole.CFrame.p).unit * configurations.Range.Value)
local ignore = {player.Character, tool:GetChildren()}
local hitPart, position = workspace:FindPartOnRay(ray, ignore, false, true)
considering my luck though, instead of the ray actually working now, it throws an error:
“Unable to cast Value to Object”.
How can I fix this issue?
EDIT: I do not know if this matters, but all of this occurs within FirstPerson, as my game is locked to that.
local ray = Ray.new(tool.Hole.CFrame.p, (mouse.Hit.p - tool.Hole.CFrame.p).unit * configurations.Range.Value)
local ignore = {player.Character, tool:GetChildren()}
local hitPart, position = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
lol posted the exact same thing at the exact same time
It still turns up the same error, and to be redundant and 100% sure that it isn’t simply a syntax issue, I mentioned each individual part of the character’s children, same thing with the tool. Thus the same error is given.
As :FindPartOnRay can already take these arguments including ignoreDescendantsInstance, it would not make a difference for the problem to replace this function with its counter function :FindPartOnRayWithIgnoreList instead.
Ignoring player.Character still turns up as “Y35X” when I print the name of the hit part, so I assumed that also ridding tool might get rid of this issue.
Yes, it prints as “Y35X” when there is no error. The only time there is an error is when I make it explicitly clear to ignore all character children too with :GetChildren()
Then there’s what you need to figure out first. Either provide your code for us to try and solve it, or debug by yourself why it prints your username instead of the name of a basepart.
Pretty sure this is an illegal argument, I never recall the ignore list of raycast functions supporting nested tables. This part needs to change. So long as you do not put any other elements after the GetChildren call, you can unpack the table and catch the returns in the table.
Aha, after studying my code some, on the server script, I accidentally put hitPart as the first argument, which is reserved for the player. So it looks like this: