Problem with InputEnded on mobile but not on pc

Hi, so i’m making a custom inventory system and i was trying to make the drag and drop system compatible for mobile players and i ran into a problem…

The problem is related to InputEnded, on PC InputEnded works if i stop clicking the button anywhere on the screen, but on mobile its only fired if i stop clicking on the button (idk how to explain it in a better way, but here’s a video)

Also part of my code:

NewTool.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch and ItemDragged == nil and Dragging == false  then
		print("Began: "..input.UserInputType.Name)
				
		Dragging =  true
		ItemDragged = NewTool
		--not relevant
	end
end)		

NewTool.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch and Dragging == true and ItemDragged == NewTool then
		print("Ended: "..input.UserInputType.Name)
				
		Dragging =  false
		ItemDragged = nil
		--not relevant
	end
end)

i would really appreciate if somebody could tell me if there’s a problem on my script or what’s happening…

1 Like

You can make it in one event instead of InputEnded

local connection 

NewTool.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch and ItemDragged == nil and Dragging == false  then
		print("Began: "..input.UserInputType.Name)
				
		Dragging =  true
		ItemDragged = NewTool
        connection = input.Changed:Connect(function()
		if input.UserInputState == Enum.UserInputState.End then
			Dragging =  false
	    	ItemDragged = nil
            print("Ended: "..input.UserInputType.Name)
            connection = nil
		end
		end)
	end
end)

any error feel free to tell me :heart:.

1 Like

It worked perfectly, Thanks!!! :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.