Screenpointtoray does not work properly on mobile version

  1. What do you want to achieve? Keep it simple and clear!

result in different positions in different places while “clicking” on the mobile version, as it should be without the emulation.

  1. What is the issue? Include screenshots / videos if possible!

I took a script already provided in roblox dev and for some reason it doesn’t work correctly in the mobile versions. Without using studio emulation the script works normally, updating the positions as I click in different places. however, I went to the emulation in roblox studio to test the mobile version and I was surprised that the results were repeating 2 times even when clicking in different places.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I saw few articles talking about this function, almost none was about the mobile version

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local mouse = player:GetMouse()
local camera = workspace.CurrentCamera

--This will create a cube facing centered at the origin of the [[Ray]] returned and facing in the same direction. The center of the cube will be one stud in front of the camera.
	local ray = camera:ScreenPointToRay(mouse.X, mouse.Y, 1)
	local cube ="Part")
	cube.Size =, 1, 1)
	cube.CFrame =, ray.Origin + ray.Direction)
	cube.Anchored = true
	cube.Parent = workspace

I had a similar issue trying to implement custom controls for a click detector replacement. I noticed the input sort of dragged behind and doubled from time to time and overall wasn’t always super predictable.

I ended up switching to UserInputService.TouchStarted and used the InputObject (passed to function in .TouchStarted)'s position instead of mouse.X/Y and that made it work more predictably. The mouse object is also considered legacy (not deprecated) and has been superseded by UserInputService/ContextActionService which guarantees better and more predictable support for cross-platform input compatibility


OOOOoooo may gaa! I didn’t know there was specific one for mobiles , i made the changes in my script and that doesn’t happen anymore on mobile , thank you very much!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.