local function FireRay(Position)
local UnitRay = Camera:ViewportPointToRay(Position.X, Position.Y)
local ray = Ray.new(UnitRay.Origin, UnitRay.Direction * 100)
local HitPart, WorldPosition = game.Workspace:FindPartOnRay(ray)
return WorldPosition
end
This is the current function that I’m using, and it works, but it return the position a little higher than
where I clicked/tapped as you can see in the picture below
local function FireEvents(Input, InputState)
local Position = RayCast(Input.Position).Position
ServerInputPosEvent:FireServer(Position, InputState)
ClientInputPosEvent:Fire(Position, InputState)
end
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if not GameProcessed then
if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
FireEvents(Input, 1)
end
end
end)
ScreenPointToRay will start 36 pixels below the top of the screen (height of the topbar/gui inset) and ViewportPointToRay starts at the top of the screen.
Input.Position gives u the screen position, which starts 36 pixels below the top of the screen.