How to detect if mobile player started touched or untouched on gui button?

How to detect if mobile player started touched or untouched on gui button?
like

if gui.StartTouched then
istouch = true
elseif gui.EndTouched then
istouch = false
end

If you don’t understand I tried to make this

script.parent.MouseButton1Down:Connect(function()
    mouse1down = true
end)

script.parent.MouseButton1Up:Connect(function()
    mouse1down = false
end)

but on Mobile

sorry for bad english

I do not have too much experience on this…, but have you at least tried the code you made on mobile?

From my experience, MouseButton1Down and MouseButton1Up still work even if you’re on mobile

3 Likes

Yes you are right but I would consider using UserInputService with InputBegan and InputEnded.

UserInputService would also work, but I think it would be better to use MouseButton1Down and MouseButton1Up since @RealingZeeKung mentioned that he wants to detect if a mobile user touched or stopped touching a GuiButton since they have event for that built-in to them

1 Like

No i don’t think MouseBUtton1Down and MouseButton1Up is works on mobile
because the mobile doesnt have mouse and you use Finger to touch it so i think it doesnt works

From my experience its working can you provide us full code?

Yes the event state it’s for a mouse, but the events work for touch input as well from a mobile device

script.Parent.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch then
		istouched = true
		event:FireServer(istouched)
	end
end)

script.Parent.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch then
		istouched = false
		event:FireServer(istouched)
	end
end)

This code i tried and it doesnt work i think i script something wrong

In this case use what @EmbatTheHybrid said before.
Use MouseButton1Down and MouseButton1Up

The code was already ok before… we are telling you if at least you are testing it on moblie

Also im talking about the part with MouseButton1Up and MouseButton1Down

1 Like

Use MouseButton1Down and MouseButton1Up, they work for Mobile input as well

5 Likes

I think that the following functions also work:

Button.Activated:Connect(function()


Button.Unactivated:Connect(function()

I think his problem is most likely path to the GuiObject not the Mouse Event at all.

You can try using playergui:GetGuiObjectsAtPosition, with events from UserInputService

Try to add new TextButton or ImageButton and insert local script as a child.

The local script:

local Button = script.Parent

Button.MouseButton1Down:Connect(function() 
print("Connected") 
end) 

Button.MouseButton1Up:Connect(function() 
print("Disconnected") 
end) 

ok ok roblox thanks
So MouseButton1Down works perfectly fine on mobile I tested it

I would recommend marking one of the posts as the solution as to help others who may have a have a similar question to yours can find the answer easily

1 Like

Are you putting an event in an if statement? That works?

His code wouldn’t have worked since you can’t put events in if statements and StartTouched and EndTouched are not real events,

The solution was eventually discovered to be MouseButton1Down and MouseButton1Up, the things OP thought only worked on computers but can also work on mobile devices with touch input