Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

FindPartOnRay isn't returning anything when I click on a part. What am I doing wrong?

Asked by 4 years ago
Edited 4 years ago

So. I'm trying to make a grappling hook. Here's my code.

It's in a local script.

local p = game.Players.LocalPlayer
repeat wait() until p.Character
local c = p.Character
local m = p:GetMouse()

m.Button1Down:Connect(function()
    --mouse hit position and making a ray so i can make a rope afterwards
    local hit = m.Hit.p
    local ray = Ray.new(c.RightHand.Position - hit.unit * 300)

    --self-explanatory
    local part, position = workspace:FindPartOnRay(ray)

    --testing where the mouse hit is
    local d = Instance.new("Part", workspace)
    d.Anchored = true
    d.Position = hit

    print(part)
end)

Whenever I test this, I click on a block and it returns nothing. The 'd' part locates itself on the block. FindPartOnRay just isn't working for me.

Any help is appreciated, thanks.

EDIT: It is working. When the ray decides to work and actually point where my cursor is pointing. WHY IN ALL OF HELL WOULD IT NOT POINT WHERE MY CURSOR IS?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I made an error when creating the Ray. Instead of putting the origin and direction I forgot to include origin.

ray = Ray.new(c.RightHand.Position, (c.RightHand.Position - hit).unit * 300)
0
ok gloveshun 119 — 4y
Ad

Answer this question