How can I make this script into a mobile-friendly script?

Hello everyone,
I have this script:

local camera = workspace.Camera
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.Z then

		player.CameraMode = Enum.CameraMode.Classic
		camera.FieldOfView = 15 

	end

end)

UIS.InputEnded:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.Z then

		player.CameraMode = Enum.CameraMode.Classic
		camera.FieldOfView = 35 
		

	end

end)

What it does is: when a player presses the “Z” key, it zooms into the character, and when the player stops pressing it the FOV returns to normal.

How can I make this into a button for mobile and therefore have the same effect? (the player presses a GUI button and then when the player stops pressing it the same thing happens as the PC one)

Thanks in advance.

UserInputService also has touch enums, you can do an elseif or use a dictionary/array with valid input enums

Hope it helped

Plus, you may want to look into conextactionservice to bindactions!

1 Like

you can check if the player has a keyboard with UserInputService
https://developer.roblox.com/en-us/api-reference/property/UserInputService/KeyboardEnabled

just check if they don’t have a keyboard then you can clone a ScreenGui in their PlayerGui and use the button in there to do the same as pressing z

2 Likes

https://developer.roblox.com/en-us/api-reference/class/ContextActionService