It’s pretty basic, but I have a staff that you click and hold to fire (sort of like a magic machine gun). It works fine on PC, but on mobile it only fires one projectile, and even then it’s kind of hit or miss whether it does it or not. It still goes where you aim it, it just doesn’t stay firing if you hold you finger down.
Local code:
local CanFire = false
local player = game.Players.LocalPlayer
local mouse = nil
function Fire()
CanFire = true
while CanFire == true do
wait()
mouse = player:GetMouse().Hit.p
if mouse ~= nil then
script.Parent.FireStaff:FireServer(mouse)
end
end
end
function EndFire()
CanFire = false
end
function UnEquip()
CanFire = false
end
script.Parent.Activated:Connect(Fire)
script.Parent.Deactivated:Connect(EndFire)
script.Parent.Unequipped:Connect(UnEquip)
I have tested the Activated and Deactivated events with a tool on a mobile device and I seem to not get any inputs.
You can use UserInputService.MouseEnabled to check if the client is on a mobile device, then you can use UserInputService.InputBegan and UserInputService.InputEnded to check if the user is touching their screen:
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.Touch then
CanFire = true
end
end)
uis.InputEnded:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.Touch then
CanFire = false
end
end)