Pls help me with mobile buttons

i have a fps game the mobile buttons are broken
screen gui > script and frame
inside frame > img button and text lable > local script (inside img button)
the script
if game:GetService(“TouchInputService”).TouchEnabled == true then
for _,v in pairs(script.Parent:GetChildren()) do
if v.ClassName == “Frame” then
v.Visible = true
end
end
end

the local script
– We must get the UserInputService before we can use it

local UserInputService = game:GetService(“UserInputService”)

– A sample function providing one usage of InputBegan

local function onInputBegan(input, gameProcessed)

if input.UserInputType == Enum.UserInputType.MouseButton1 then

print(“The left mouse button has been pressed!”)

end

end

UserInputService.InputBegan:Connect(onInputBegan)
i used local script from UserInputService

Screenshot 2020-12-23 125904
Screenshot 2020-12-23 125909

1 Like

It’d be nice if you included screenshots, and made the script easier to read using triple `'s on each end.

You haven’t really provided any information on what the problem is either, please elaborate.

1 Like

ok i just did added the imgs of scripts

Wouldn’t it be better to use ContextActionService? As BindAction has a parameter to create a mobile button when you’re binding a function

  • You shouldn’t have a script in your UI. Turn that into a local script or use the one you already have.
  • I would also recommend the Instance:IsA() function to check the type of instance. Your code works too, though IsA can also do super classes which is helpful.
  • You might want to look into ImageButton.Activated and RemoteEvents.

tried the local script thing also how to i make it only visible to mobile?

Check on a local script if UserInputService.TouchEnabled is true. If it’s true, make the UI visible. I would recommend doing it through ScreenGui.Enabled, though Frame.Visible with a loop works too.
Note: if you use screengui.enabled, you should only put mobile UI inside the screengui.