Help with mobile crosshair for ranged function

Hello, I am making a randomizer game similiar to item asylum and i was wondering if anyone could make it so if you’re on mobile, instead of shooting normally, aka where you click is, bla bla bla, i was wondering if anyone could help me with making it shoot where the crosshair is, if you’re on mobile. The crosshair is a imagelabel inside of a frame in a screengui. I made it so it pops up if you equip the weapon, but i do not know how to make it so it actually shoots there. Please do not optimize or change unnecessary parts of the script, as it works perfectly and simply, and i like it like that, just change it so you can make it shoot where the crosshair is if you’re on mobile.

Local script:

local Tool = script.Parent
local RE = Tool.RemoteEvent
local Anim = Tool.Animation
local Plr = game.Players.LocalPlayer
local Char = Plr.Character
local Hum = Char.Humanoid
local AnimTrack = Hum:LoadAnimation(Anim)
local debounce = false
local ShootAnim = Tool.Shoot
local Mouse = Plr:GetMouse()
local isMobile = game:GetService("UserInputService").TouchEnabled
local isDesktop = game:GetService("UserInputService").KeyboardEnabled

Tool.Equipped:Connect(function()
	AnimTrack:Play()
	AnimTrack.Looped = true
	if isMobile then
		Plr.PlayerGui["Mobile crosshair"].Enabled = true
	end
end)

Tool.Unequipped:Connect(function()
	AnimTrack:Stop()
	Plr.PlayerGui["Mobile crosshair"].Enabled = false
end)

Tool.Activated:Connect(function()
	if debounce == false then
		debounce = true
		local Shoot = Hum:LoadAnimation(ShootAnim)
		Shoot:Play()
		RE:FireServer(Mouse.Hit.Position)
		task.wait(1.5)
		debounce = false
	end
end)

Server script

local tool = script.Parent

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Plr, MousePos)
	tool.Handle["Pistol Shoot"].Playing = true
	local RayParams = RaycastParams.new()
	RayParams.FilterDescendantsInstances = {Plr.Character}
	RayParams.FilterType = Enum.RaycastFilterType.Exclude
	
	if tool.Handle then
	local RayCastResult = workspace:Raycast(tool.Handle.Position, (MousePos - tool.Handle.Position) * 300, RayParams)
	
	if RayCastResult then
		local RayInstance = RayCastResult.Instance
		local Model = RayInstance:FindFirstAncestorOfClass("Model")
		
		if Model then
			if Model:FindFirstChild("Humanoid") then
				if RayInstance.Name == "Head" then
					Model:FindFirstChild("Humanoid"):TakeDamage(40 * Plr.AttackMultiplier.Value)
					tool.Handle.Headshot.Playing = true
				else
					Model:FindFirstChild("Humanoid"):TakeDamage(10 * Plr.AttackMultiplier.Value)
					end
				end
			end
		end
	end
end)

Mouse.Hit.Position will return a 3D Position however AbsolutePosition will return a 2D Position, you will need to use ScreenPointToRay.

local Camera = workspace.CurrentCamera

local ImageLabel = Instance.new("ImageLabel")

print(Camera:ScreenPointToRay(ImageLabel.AbsolutePosition.X, ImageLabel.AbsolutePosition.Y))

The imagelabel is already created, it doesn’t need to be added, + where and why am i supposed to add your part of code?
image

The position of the imagelabel is {-0.14, 0},{-0.34, 0}, if that’d help.

All I did was provide a snippet and how you can utilize Camera:ScreenPointToRay(ImageLabel.AbsolutePosition.X, ImageLabel.AbsolutePosition.Y) to raycast as it returns a Ray with Unit and Direction.

Ooh, alright, my bad i didn’t understand, thank you.

-- ServerEvent
(function(MousePos: Vector3 | Ray)
	local _RaycastResult = nil
	if typeof(MousePos) == "Vector3" then
		_RaycastResult = workspace:Raycast(Tool.Handle.Position, (MousePos - Tool.Handle.Position)* 300)
	else
		_RaycastResult = workspace:Raycast(Tool.Handle.Position, (MousePos.Direction - Tool.Handle.Position)* 300)
	end
end)(_Ray)