Attempt to perform arithmetic (sub) on table and Vector3

Hello, I’m Matt
Currently I’m working on making my game mobile supported, so I made a basketball that where-ever you tap it uses TJP to go to the spot you tapped.

it works fine on computer and even when testing it through the device screen but on mobile I get an error!

Error:

I’ve looked on Google and DevForum posts and ScriptingHelpers and I can’t find a solution, I even checked the second page of my Google Search.

Local Script:

local PlayersService = game:GetService("Players")

local player = PlayersService.LocalPlayer
local mouse = player:GetMouse()

local basketball = script.Parent
local basketballHandle = basketball:FindFirstChild("Handle")
local shootBasketballRE = basketball:WaitForChild("ShootBasketball")

local cooldown = false
local equipped = false

basketball.Equipped:Connect(function()
	equipped = true
end)

basketball.Unequipped:Connect(function()
	equipped = false
end)

basketball.Activated:Connect(function()
	if cooldown == false then
		
		cooldown = true
		
		shootBasketballRE:FireServer(mouse.Hit.p)
		
		wait(6.5)
		
		cooldown = false
		
	end
end)

-- Main Mobile Code
if game:GetService("UserInputService").TouchEnabled then
	print("Is mobile!")
	game:GetService("UserInputService").TouchTapInWorld:Connect(function(touchPos)
		if equipped == true then
			if cooldown == false then

				cooldown = true

				shootBasketballRE:FireServer(touchPos)
				print(tostring(touchPos))

				wait(6.5)

				cooldown = false

			end			
		end
	end)
end

Server:

local PlayersService = game:GetService("Players")
local RunService = game:GetService("RunService")
local debris = game:GetService("Debris")

local basketball = script.Parent
local basketballHandle = basketball:FindFirstChild("Handle")
local shootBasketballRE = basketball:WaitForChild("ShootBasketball")

local t = 1

shootBasketballRE.OnServerEvent:Connect(function(player, mousePos)
	
	local char = player.Character
	
	if char then
		
		local hrp = char:FindFirstChild("HumanoidRootPart")
		
		if hrp then
			
			basketballHandle.Transparency = 1
			
			local g = Vector3.new(0, -workspace.Gravity, 0)
			local x0 = hrp.CFrame * Vector3.new(0, 2, -2)
			
            -- Error here!
			local v0 = (mousePos - x0 - 0.5 * g * t * t)/t
			
			local cloneBall = basketballHandle:Clone()
			cloneBall.Velocity = v0
			cloneBall.CFrame = CFrame.new(x0)
			cloneBall.CanCollide = true
			cloneBall.Transparency = 0
			cloneBall.Name = "Basketball"
			cloneBall.Parent = workspace
			
			debris:AddItem(cloneBall, 5)
			
			coroutine.resume(coroutine.create(function()
				wait(5)
				basketballHandle.Transparency = 0
			end))
			
		end
		
	end
	
end)

Thank you for reading, please comment if you have any question!

1 Like

Pretty sure it’s this line alone:

local v0 = (mousePos - x0 - 0.5 * g * t * t)/t

• Elaborate if mousePos is X,Y,Z or X,Y
• X0 is a CFrame and is a bunch of values (The table) that you’re trying to subtract with 0.5
• For further debugging I suggest you go ahead and print each value like this:

warn(mousePos)
print("")
warn(X0)
print("")
warn(g)
print("")
warn(t)

It’s the MousePos that’s breaking the script

Hey yes it’s me the dummy, I found out I had to use TouchLongPress so if you have the same issue as me there’s your solution! : )

Thanks for the help, it helped like a lot!

Ooh ok, I thought it was mostly the mousePos or the CFrame, glad you found the reason.

We’ll I wouldn’t have found it out if you didn’t tell me to print (I always forgor to print) I wouldn’t have solved it.

1 Like