I have a gun which similarly shoots like mm2’s gun. The problem with this gun is that it sometimes doesn’t shoot when you’re on mobile. Compared to mm2’s gun, it ignores the mobile user’s thumbstick.
Client Code:
UIS.TouchTapInWorld:Connect(function(position, processedByUI)
local touchstickEnd = player.PlayerGui:WaitForChild("TouchGui"):WaitForChild("TouchControlFrame"):WaitForChild("DynamicThumbstickFrame"):WaitForChild("ThumbstickEnd")
if math.abs((mouse.X - touchstickEnd.AbsolutePosition.X)) < 18 or math.abs((mouse.Y - touchstickEnd.AbsolutePosition.Y)) < 18 then
else
if cooldown then
return
end
if processedByUI then
return
end
if not equipped then
return
end
gunFiredMobileEvent:FireServer(position, workspace.CurrentCamera:ViewportPointToRay(position.X, position.Y))
handle.Shoot:Play()
cooldown = true
task.wait(.5)
handle.Reload:Play()
handle.Reload.Ended:Wait()
cooldown = false
end
end)
Server Code:
gunFiredMobileEvent.OnServerEvent:Connect(function(player, position, unitRay, mh)
if player.Character.Humanoid.Health <= 0 then
return
end
local origin = handle.Hole.Position
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 300)
local hitPart, worldPosition = workspace:FindPartOnRay(ray)
local intersection = hitPart and worldPosition
local distance = (origin - intersection).Magnitude
local bullet = objects.Bullet:Clone()
bullet.Size = Vector3.new(.15, .15, distance)
bullet.CFrame = CFrame.new(origin, intersection) * CFrame.new(0, 0, -distance / 2)
bullet.Parent = workspace.Bullets
handle.Shoot:Play()
coroutine.wrap(function()
task.wait(.5)
handle.Reload:Play()
end)()
if hitPart then
local humanoid = hitPart.Parent:FindFirstChild("Humanoid") or hitPart.Parent.Parent:FindFirstChild("Humanoid")
local hrp = hitPart.Parent:FindFirstChild("HumanoidRootPart") or hitPart.Parent.Parent:FindFirstChild("HumanoidRootPart")
if humanoid and humanoid ~= player.Character.Humanoid and humanoid.Health > 0 then
for i, particle in pairs(confetti:GetChildren()) do
if particle:IsA("ParticleEmitter") then
local newParticle = particle:Clone()
newParticle.Parent = hrp
newParticle:Emit(45)
end
end
humanoid.Health -= 110
handle.Hit:Play()
end
end
ts:Create(bullet, TweenInfo.new(.4), {Transparency = 1}):Play()
debris:AddItem(bullet, .41)
end)
I’ve spent days researching on how to ignore the thumbstick when using a gun on mobile. The code above is what I’ve gained from the researching.
(Will respond to replies in the morning)