So I’m attempting to make a shop/inventory system that is very mobile friendly, I have tried many things like: Mouse.Move, UserInputService etc… And most of the system ends up glitchy and problematic…
Also Mouse.Move works perfectly on PC but what I’m trying to achieve is that when you click on a button a hovergui appears and doesn’t go away until you click somewhere else.
What I have been trying to achieve is something like this:
If you can/know how to make a system similar to this please reply and help me out
You could use UserInputService:TouchTap to listen for when the user touches the screen. When this happens, clear all of the hover GUI elements. After this is processed you can then process any button connections to make a new hovergui appear.
Okay I managed to make it somewhat work on a blank game, The only real problem I’m facing right now is the decision to make it so there are 2 separate script for Mobile And For PC, for mobile using UserInputService and For PC Script.Parent.MouseEnter and Script.Parent.MouseLeave
Video of how it works (Same On Mobile)
Here’s how I did it:
Whenever UIS.InputBegan is called it releases a value called _gameProcessed which is a boolean
true always means that the element you clicked on is a GUI after that I get the Mouse Property and get its position With: PlayerGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y)
After that, I loop through the objects within that position and look for a button with a random tag I set and that’s pretty much it
If you want to look at the code here it is:
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
Mouse = Player:GetMouse()
local function onInputBegan(input, _gameProcessed)
if _gameProcessed then
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
script.Parent.TextLabel.Visible = true
local Btn = PlayerGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y)
for _,v in Btn do
print(v)
if v:IsA("TextButton") and v:HasTag("HoverButton") then
script.Parent.TextLabel.Text = v.Text
end
end
script.Parent.TextLabel.Position = UDim2.new(-.59,Mouse.X ,-.25,Mouse.Y)
end
else
script.Parent.TextLabel.Visible = false
end
end
UIS.InputBegan:Connect(onInputBegan)