I’ve made a function that gets a target from the users mouse location, however the code breaks if my mouse is pointing at the sky. How can i fix that?
Code:
local function getTarget()
local pos = UserInputService:GetMouseLocation()
raycastParams.CollisionGroup = "Characters"
local Ray = workspace:Raycast(game.Workspace.CurrentCamera.CFrame.p, game.Workspace.CurrentCamera:ViewportPointToRay(pos.x, pos.y, 0).Direction * 1000, raycastParams)
if Ray.Instance then
return Ray.Instance
end
return nil
end
local function getTarget()
local pos = UserInputService:GetMouseLocation()
raycastParams.CollisionGroup = "Characters"
local Ray = workspace:Raycast(game.Workspace.CurrentCamera.CFrame.p, game.Workspace.CurrentCamera:ViewportPointToRay(pos.x, pos.y, 0).Direction * 1000, raycastParams)
if Ray then
return Ray.Instance
end
return nil
end