I have this script for wands, I'm trying to make it mobile-friendly but to no success, if anyone can help it would be greatly appreciated.
local tool = script.Parent
local UIS, Player, Camera = game:GetService("UserInputService"), game:GetService("Players").LocalPlayer, workspace.CurrentCamera
local MP, MD = nil, nil
function GetMousePoint(X, Y)
local RayMag1 = Camera:ScreenPointToRay(X, Y) --Hence the var name, the magnitude of this is 1.
local NewRay = Ray.new(RayMag1.Origin, RayMag1.Direction * 2500)
local Target, Position = workspace:FindPartOnRayWithIgnoreList(NewRay, {Player.Character, workspace.FlyingSpells})
return {Target, Position}
end
local downEvent = function()
if MD == true then
script.Parent.Comm:FireServer(true, MP[2], MP[1])
wait(.25)
end
end
UIS.InputBegan:Connect(function(input, pro)
if pro or script.Parent.Parent ~= Player.Character then return end
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Q then
print("keyboard")
elseif (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) and MP ~= nil then
MD = true
while MD do
downEvent()
end
end
end)
UIS.InputChanged:Connect(function(input, pro)
if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
MP = GetMousePoint(input.Position.X, input.Position.Y)
end)
UIS.InputEnded:Connect(function(input, pro)
if input.UserInputType ~= Enum.UserInputType.Keyboard then
MP = GetMousePoint(input.Position.X, input.Position.Y)
if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
MD = false
end
end
end)

1 comment
Found the answer, just needed to check if they were on a TouchEnabled device and find the input position from there.