I have a tool that has two different functions connected to its .Activate and .Deactivate events. It’s important to my game’s gameplay that both the .Activated and .Deactivated events can be fired separately at will.
It works perfectly fine on computer, but on mobile I have to tap the screen in order for the tool to fire the .Activated event, which means the .Deactivated event is always fired immediately afterwards. I’m not able to press and hold to activate the tool, so it’s impossible to fire the .Activated and .Deactivated events separately.
How would I go about fixing this?
I’ve seen other games working perfectly fine with pressing and holding to activate, but I have no idea how they did it, or if maybe it used to work on an older version of studio and now doesn’t for some reason.
Could you send your activate and deactivate code?
I found a cheeky way to achieve this. This was tested on Roblox Studios Device Emulator so im not sure if it would work on an actual mobile device but its an emulator so i don’t see why not
local UserInputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Tool = script.Parent
local hold = false
local isMobile = UserInputService.TouchEnabled
if isMobile then
UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if Character:FindFirstChild(Tool.Name) then
hold = true
print(hold)
end
end)
UserInputService.InputEnded:Connect(function(input, gpe)
if gpe then return end
if Character:FindFirstChild(Tool.Name) then
hold = false
print(hold)
end
end)
end
- Checks if the input type is mobile. If it is then we set the variable hold to true and then you can activate whatever you want as long as that hold is true
RunService
or just run it in the InputBegan / Ended.
This actually worked surprisingly well. I didn’t think it would work when I first read it because it would still activate when the player tried moving their camera, but I did a quick check in another game that seems to have this issue solved already, and they still allowed tools to activate while moving the camera. In fact, I think that if they changed that, it would make gameplay a lot more difficult.
That was my only concern, so with that out of the way, this solution turned out to be perfect.
Thanks so much for your help!
I only made small changes to your example (I’m mentioning this for future readers). Instead of giving it to one specific tool, I put the script inside of StarterPack and used Character:FindFirstChildWhichIsA("Tool")
inside the InputBegan/InputEnded events to determine which tool the player is actively using, then manually activated/deactivated the tool.
1 Like