Hi, as a novice script developer, I want to ask how to turn button clicks into a computer key? After some trial and error, I’ve discovered that the easiest approach to create mobile buttons (Mobile Support) is to translate or convert (Gui) Button Clicks into Keys—more precisely, PC Keys like E, R, MouseButton1, etc. Using or Employing UserInputService.
I’ve tried searching on DevForum and even using ChatGPT, but I’m still not sure how. If someone could show me or maybe teach me, that would be really appreciated.
Here is some code that matches my skill level
local UserInputService = game:GetService("UserInputService")
local button = script.Parent
-- Function to simulate mouse button press
local function simulateMouseClick()
local inputBegan = {}
inputBegan.UserInputType = Enum.UserInputType.MouseButton1
UserInputService.InputBegan:Fire(inputBegan)
end
button.MouseButton1Click:Connect(function()
-- Simulate pressing the left mouse button
simulateMouseClick()
end)
Most times it bugs out. and gives me an error.