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

My raycasting for a beam is not hitting?

I am making a beam script and the ray casting seems to be going through stuff it shouldn't.

local ignoreList = {mob, game.Workspace.IgnoreFolder}
local castTrack = mob.Humanoid:LoadAnimation(script.Cast)
castTrack:Play()
wait(.5)
local base = spellEffect()
-- spellEffect() returns an object that is where the beam should originate.
local spawnFrame = base.CFrame
wait(.5)

local ray = Ray.new(spawnFrame.p,(spawnFrame.p-plr.Character.Torso.Position).unit*50)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray,ignoreList,false, true)
local distance = (spawnFrame.p - position).Magnitude
print(distance)
print(part)

the distance always returns 50 and part always returns nill Thank you

1 comment

0

there are no output errors btw

1 answer

✓ Accepted answer

The way ignoreLists work is they do not ignore the children of the instances, only the exact ones you specify. It might be annoying, but usually helpful. This is in contrast to the regular ignore parameter with :FindPartOnRay(), which does ignore the children of the one instance.

Your options:

--list the ignoreFolder yourself

local ignoreList = {mob, unpack(workspace.IgnoreFolder:GetChildren())}

--OR

--use the simple ignore somehow

mob.Parent = workspace.IgnoreFolder
workspace:FindPartOnRay(ray,workspace.IgnoreFolder,false, true)
--mob.Parent = --previous parent?

Most importantly, your ray direction seems to be the opposite of what you want. If you want it to hit the player torso you should subtract the base from the torso. Just how it works! Simple fix:

local ray = Ray.new(spawnFrame.p,(plr.Character.Torso.Position-spawnFrame.p).unit*50)

Cheers

1 comment

0

thank you!

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