How could I go about adding mobile compatibility to this?

Hi, so I was told recently that some code I wrote up awhile back does not function on mobile, and I’ve been a bit puzzled as to how I can add mobile compatibility.

Basically, it’s a ‘detain’ tool. Players can jail other players upon clicking them. Any help appreciated, thanks.

game:GetService("ContextActionService"):BindAction("MouseMoved",function()
	if equipped then
		local unit_ray = mouse.UnitRay
		local ray = Ray.new(unit_ray.Origin, unit_ray.Direction * 200)
		local hit, p = game.Workspace:FindPartOnRay(ray)
		local offender = hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)
		hovered_player = offender and offender ~= player and offender:GetRankInGroup(4378552) < 12 and offender
		if hovered_player then
			box.Adornee = hovered_player.Character
		else
			box.Adornee = nil
		end
	end
end, false, Enum.UserInputType.MouseMovement)

EDIT: I just realized I can bind another action type for this, like TouchBegan or something among those lines, assuming that’ll fix it, I’ll try adding that now.

Yes, I was going to recommend using Enum.UserInputType.Touch and UserInputStates Began, Ended, and Changed in conjunction with ContextActionService methods.

2 Likes