I send the mouse position from the client to the server with a remote event and then create a ray on the server. The mouse position does get sent to the server, the ViewRay variable also gets created, however the ray returns nil for some reason. Why? I am standing right next to the part I want to hit, so I can’t be too far away.
Client script:
UserInputService.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
SomeRemote:FireServer(UserInputService:GetMouseLocation())
end
end)
Server script:
SomeRemote.OnServerEvent:Connect(function(Player, MousePosition)
local ViewRay = workspace.Camera:ViewportPointToRay(MouseLocation.X, MouseLocation.Y, 0)
local ray = workspace:Raycast(ViewRay.Origin, ViewRay.Direction * 300)
print(ray)--Prints nil
end)