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

raycast not finding a part?

Asked by 5 years ago

so i have a local script which fires a remote function inside of itself to check if theres a part infront of the player or not, the remote event IS fired but it always prints "not found" even while i stand infront of a wall

01script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,command)
02    local char = plr.Character
03 
04    if command == "Check" then
05        local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0,0,-1.5))
06        local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,char:GetChildren(),false,true)
07 
08        if hit then
09            print(hit.Name)
10            local bruh = Instance.new("Part",workspace)
11            bruh.Name = "Bruh"
12            bruh.Anchored = true
13            bruh.CFrame = CFrame.new(position)
14        elseif not hit then
15            print("not found")
16        end
17    end
18end)

anybody knows what im doing wrong??

0
Your ignore list, it's ignoring the character? killerbrenden 1537 — 5y
0
i'm pretty sure it is but i'm gonna try to change it to just findpartonray kayser901 2 — 5y
0
changing it to game.Workspace:FindPartOnRay(ray,char,false,true) has the same issue kayser901 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

so i gave up on trying that and instead i went with a different approach

01script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,command)
02    local char = plr.Character
03 
04    if command == "Check" then
05        local offset = Vector3.new(0,0,-1.5)
06        local ray = Ray.new(char.HumanoidRootPart.Position,(char.HumanoidRootPart.CFrame*CFrame.new(offset).lookVector))
07        local hit, position = game.Workspace:FindPartOnRay(ray,char,false,true)
08 
09        if (char.HumanoidRootPart.Position - position).magnitude < 3 then
10            print("close enough")
11        elseif (char.HumanoidRootPart.Position - position).magnitude > 3 then
12            print("too far")
13        end
14    end
15end)

this one here seems to work "perfectly". i haven't tried anything complicated with it yet but i think i can use it for what im trying to do

Ad

Answer this question