Hello, not even 2 hours later and I’m back haha. Anyone know how to do a KeyCode function, but for Mobile users? I’ve been looking around not too many good tutorials, lol. Suggestions below. Here is the code:
local PressE = game.Workspace.PressE
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
UIS.InputBegan:Connect(function(input, gpe)
if input.KeyCode == Enum.KeyCode.E then
if (PressE.Position - root.Position).Magnitude < 12 then
player.PlayerGui.ScreenGui.Enabled = true
end
end
end)
I dont fully understand what youre trying to accomplish. What “Key” is there for a mobile user to press? The only thing i can think of is make the button able to enable the screengui when pressed.
Since there is no “Key” on mobile to press, to open a GUI, I would just make a Button that opens the GUI. In that case here is a post that explains that:
Yes, you can index the button using local. The local script that does this should be in the button itself. Im assuming youre dealing with a BillboardGui. It might act differently but i dont know, i dont fiddle with BillboardGuis that often
Yup, if you want it to open and close, then you can do this:
local button = script.Parent
local screengui = game.Players.LocalPlayer.PlayerGui.ScreenGui
button.Activated:Connect(function()
if screengui.Enabled == true then
screengui.Enabled = false -- closes gui if it is open
else
screengui.Enabled = true -- else, opens it
end
end)
Just insert a TextButton, place / size it over the Frame, and then make it invisible.
I reccomend inserting the button inside the Frame, Sizing it to {1,0}.{1,0} and then setting BackgroundTransparency to 1 and Text to blank. Now the frame should look the same, but act as a button. But when making the script, make sure you index the button, not the frame!
local button = script.Parent
local screengui = game.Players.LocalPlayer.PlayerGui.ScreenGui
button.Activated:Connect(function()
screengui.Enabled = not screengui.Enabled -- closes gui if it is open
end)
I just realized, I actually have a billboard attached which when u press E it opens and closes the GUI so I don’t don’t know what to do now. What I’m trying to achieve is a button to open a GUI on mobile, Ive already got one for desktops.
I suggest making a GUI in StarterGui which when you press will open the BillboardGui, the only downside would be of course the KeyCode you made will be useless as there is not really an official way to make the GUI for mobile users only if I’m correct.
So if i’m reading you correctly, you want to make a billboard gui visible when it’s tapped on mobile, OR E is pressed on PC?
in that case you could do something like…
local button = script.Parent
local screengui = [wherever the billboardgui is]
KeyBindings = {}
KeyBindings['E'] = function() screengui.Enabled = not screengui.Enabled end
UIS.InputBegan:Connect(function(input, gpe)
if KeyBindings[Input.Keycode.Name] and not gpe then
KeyBindings[Input.Keycode.Name]()
end)
button.Activated:Connect(function()
KeyBindings['E'] ()
end)
you can sort of by checking if there’s touchscreen, and if there’s an accelerometer, as all mobile devices have that, but i’m pretty sure no touchscreen monitors do
sadly there’s no IsOnMobile API
The Billboard GUI is in the part where you press E. My goal here is I want the open/close to work on mobile since I’ve already gotten a working one on PC, sorry for the confusion.