Hello! I am working on a script that tells the player what object they are looking at. I made a script that casts a ray from the player's head to their mouse's 3d position. Then, I used FindPartOnRay() to get the part that the ray hit. This is not working. Here is the code:
local RunService = game:GetService("RunService") local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() repeat wait() until Player.Character local Character = Player.Character local Head = Character:FindFirstChild("Head") RunService.RenderStepped:Connect(function() local MousePos = Mouse.Hit.p local Origin = Head.Position local ray = Ray.new(Origin, MousePos) local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray, Character) print(Hit) end)
Can anyone tell me what I am doing wrong? Is there a better way to do this?