How Would I Make This Throwable Tool Mobile-Friendly?

Sorry If this is in the wrong topic.
I’m planning on making a new project based on throwable tools. I’ve managed to make a ball which flies where you click, but the problem is it isn’t mobile friendly. Tapping where I want it to hit only fires it in one direction, and I’m not sure what I need to add/include to make it work identically to how it works on PC.

Code:

Local Script

local SuperBloxyBall = script.Parent
local FireBallEvent = game.ReplicatedStorage.FireBall
local Debounce = false

SuperBloxyBall.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function() ---Pretty sure this doesn't work on mobile correctly
		if not Debounce then
			Debounce = true
			FireBallEvent:FireServer(SuperBloxyBall.Handle.Position, Mouse.Hit.p) --Mouse.Hit.p the issue?
		else
			wait(2)
			Debounce = false
		end
	end)
end)

Server Script

local FireBallEvent = game.ReplicatedStorage.FireBall
local Speed = 500
local db = false
FireBallEvent.OnServerEvent:Connect(function(player, HandlePos, MouseHitPos)
	local SuperBloxyBall = game.ServerStorage.ToClone:Clone()
	SuperBloxyBall.Name = "Ball"
	SuperBloxyBall.Position = HandlePos
	SuperBloxyBall.Parent = workspace

	
	local distance = (MouseHitPos - HandlePos).Magnitude
	SuperBloxyBall.CFrame = CFrame.new(HandlePos, MouseHitPos)  --Set Clone's CFrame
	SuperBloxyBall.Velocity  = SuperBloxyBall.CFrame.LookVector * Speed --The firing of the ball, the part that doesn't work how I'd like it to
	
	
	
	SuperBloxyBall.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(1)
		end
	end)
end)

Help much appreciated

I’d reccomend you to use Inputservice.Touchbegan to do that. It will return an inputobject, from wich you can get it’s position (InputObject.Position), and then to use CurrentCamera.ScreenToWorlPoint. The script should already know the player’s position, and now it knows where the player wants to throw it. After that it’s up to you on how you want the ball to fly.

1 Like

The Mouse object is deprecated and shouldn’t be used in any new work, consider switching to UserInputService and firing a ray using the GetMouseLocation method to find the position, then firing that instead of Mouse.Hit.p.

2 Likes