Recently I’ve been trying to implement mobile support into my game. Basically, when the player presses the shoot button and holds it down, the player repeatedly shoots the weapon until the button is un-pressed. Problem is, if the player drifts their finger too far away from the button, mousebutton1up doesn’t register. So to compensate, I just made it to when the mouse in general is un-clicked, the player stops firing.
Only problem with this is that when the player taps anywhere else on the screen while shooting, mousebutton1up is fired, thus making the weapon stop shooting
As you can see, I didn’t stop pressing shoot, but the fact that I stopped walking made me stop shooting. Does anyone know a way to fix this?
Bumping this up since it’s also an issue I’m having, TLDR is if you are holding for example an “Attack” button and you are walking, and you stop walking your attack button stops being held for some reason
I’m not sure if this is an issue with how Roblox detects when a button is pressed or released, but I recommend taking a look at this module—it might help you out.
No, he uses ImageLabels and the Touch events from UserInputService. I chose to do it this way precisely because the events from ImageButtons sometimes behave in a strange way.
Perhaps one way you could do this is to see where the input ended, and if it falls within the range of where you button if located, you can end the shooting
Hello everyone 3 years later. For anyone coming to this issue in the future, it was solved by separating logic from the right side of the screen from the left side of the screen.
I solved this by ONLY listening to the players InputEnded() input if it’s on the right side of the screen here:
local UserInputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
local function OnButtonPressed(Input)
if Input.UserInputType == Enum.UserInputType.Touch then
local X = Input.Position.X
local ScreenWidth = Camera.ViewportSize.X
local IsRightHalf = X > (ScreenWidth / 2)
if IsRightHalf then
print("Pressed on the right half of the screen")
else
print("Pressed on the left half of the screen")
end
end
end
UserInputService.InputBegan:Connect(OnButtonPressed)