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

How to cast a Ray in front of character?

Asked by 5 years ago

Prints nil and I'm surrounded by parts.

local char = workspace:WaitForChild("papasherms")
local newRay = Ray.new(
    char:GetPrimaryPartCFrame().p, 
    (char:GetPrimaryPartCFrame().p - (char:GetPrimaryPartCFrame() * CFrame.new(char.PrimaryPart.Size.X/2,0,0)).p).unit * 500
)

spawn(function()
    while (wait(1)) do
        local hit, pos, normal = workspace:FindPartOnRay(newRay, char)
        print(hit)
    end    
end)

1 answer

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

I think you should use a LocalScript, put a LocalScript inside StarterPlayer > StarterCharacterScripts, and paste this:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

spawn(function()
    while wait(1) do
--tuple FindPartOnRay( Ray ray, Instance ignoreDescendantsInstance, bool terrainCellsAreCubes, bool ignoreWater ) 
        local Hit, Pos, Normal = workspace:FindPartOnRay(
            Ray.new(
                Character.HumanoidRootPart.Position,
                Character.HumanoidRootPart.CFrame.lookVector * 500
            ),

            Character
        )

        print(Hit, Pos, Normal)
    end
end)

Now, please read the script carefully and try to understand what's going on, this might help you in the future. Hope this helped!

Ad

Answer this question