New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why is my Ray only detecting the baseplate and nothing else?

Asked by 5 days ago

So I was learning RayCasting and I came across an issue.

local mouse = game.Players.LocalPlayer:GetMouse()

local ray = Ray.new(script.Parent.Handle.Position,Vector3.new(mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z))

mouse.Button1Down:Connect(function()
    local partThatHit = workspace:FindPartOnRay(ray)
    print(partThatHit)
end)

The script worked, but it only printed "Baseplate". I clearly pointed it to a Part, not a Model

I'm new to Rays and I need help. Can someone please give me a hand?

1 answer

Log in to vote
1
Answered by 5 days ago
Edited 5 days ago

You need a new ray every time you fire the event. Otherwise it will be using the same ray.

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    local ray = Ray.new(script.Parent.Handle.Position,Vector3.new(mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z))
    local partThatHit = workspace:FindPartOnRay(ray)
    print(partThatHit)
end)

0
Tysm! Sensei_Developer 182 — 5d
Ad

Answer this question