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!