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 6 years ago

Prints nil and I'm surrounded by parts.

01local char = workspace:WaitForChild("papasherms")
02local newRay = Ray.new(
03    char:GetPrimaryPartCFrame().p,
04    (char:GetPrimaryPartCFrame().p - (char:GetPrimaryPartCFrame() * CFrame.new(char.PrimaryPart.Size.X/2,0,0)).p).unit * 500
05)
06 
07spawn(function()
08    while (wait(1)) do
09        local hit, pos, normal = workspace:FindPartOnRay(newRay, char)
10        print(hit)
11    end   
12end)

1 answer

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

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

01local Player = game:GetService("Players").LocalPlayer
02local Character = Player.Character
03 
04spawn(function()
05    while wait(1) do
06--tuple FindPartOnRay( Ray ray, Instance ignoreDescendantsInstance, bool terrainCellsAreCubes, bool ignoreWater )
07        local Hit, Pos, Normal = workspace:FindPartOnRay(
08            Ray.new(
09                Character.HumanoidRootPart.Position,
10                Character.HumanoidRootPart.CFrame.lookVector * 500
11            ),
12 
13            Character
14        )
15 
16        print(Hit, Pos, Normal)
17    end
18end)

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