Hello, I have a click-on-screen script to get a currency but for mobile, whenever they try to move the screen(their intention being not clicking), it triggers anyways. Could you help me fixing that? Here’s the script :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local Event = ReplicatedStorage.Misc:WaitForChild("Clicked")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local function onClicked(action, inputState, inputObject)
if action == "Clicked" then
if inputState == Enum.UserInputState.Begin then
Event:FireServer()
return Enum.ContextActionResult.Pass
end
end
end
ContextActionService:BindAction("Clicked", onClicked, false, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR2, Enum.UserInputType.Touch)
Create a button gui somewhere on the screen that’ll have the same intentions, change the visible value to false. Check if the player is on mobile, if they are, then change the visible value to true. For mobile players, instead of clicking on the screen, they’d have to click on the button gui.
Hmm, I could’ve done that but this is not really what I want. Fine, I’ll not just try many days to get something that could’ve been fixed in some seconds. Thank you anyways!
local UserInputService = game:GetService('UserInputService')
UserInputService.TouchTap:Connect(function()
onClicked(action, inputState, inputObject)
end)
“The TouchTap event fires when the user touches/taps their finger on the screen on a TouchEnabled device.”
Also if you want to avoid the event being fired when a player presses on a ui object you can use TouchTapInWorld: UserInputService | Documentation - Roblox Creator Hub