How do you add mobile support to this script?

Hello, devs!
Does anyone know how I can add mobile support using starter GUI to this script?
There is also another problem where I cannot turn the valve if I press A, does anyone have an idea of what’s causing the problem?

Script in StarterGui

local player = game.Players.LocalPlayer or game.Players.PlayerAdded.Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local holding = false
local e = 'nil'


repeat game:GetService("RunService").Stepped:Wait() until game.Players.LocalPlayer
local player = script.Parent.Parent
local mouse = player:GetMouse()
local selecting = false
local valve

mouse.Button1Up:Connect(function()
	if selecting == true then
		valve = mouse.Target
		if valve.Using.Value == false and valve.Parent == workspace.Valves and script.Parent.IsUsingValve.Value == false then
			if box then
				box:Destroy()
			end
			valve.Using.Value = true
			script.Parent.IsUsingValve.Value = true
			local camera = workspace.CurrentCamera
			local tweenservice = game:GetService('TweenService')
			local cf = camera.CFrame
			repeat
				wait(.01)
				camera.CameraType = Enum.CameraType.Scriptable
			until camera.CameraType == Enum.CameraType.Scriptable
			character.HumanoidRootPart.Anchored = true
			script.Parent.ValveUI.Enabled = true
			tweenservice:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out), {CFrame = valve.offset.WorldCFrame}):Play()
			repeat
				wait(.01)
			until valve.Orientation.X > 60
			wait(1.5)
			script.Parent.ValveUI.Enabled = false
			valve.Turn:Play()
			valve.Parent = workspace.Valves.Completed
			valve.Using.Value = false
			wait(0.3)
			tweenservice:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out), {CFrame = cf}):Play()
			valve = nil
			wait(1)
			script.Parent.IsUsingValve.Value = false
			character.HumanoidRootPart.Anchored = false
			repeat
				wait(.01)
				camera.CameraType = Enum.CameraType.Custom
			until camera.CameraType == Enum.CameraType.Custom

		end
	end
end)

mouse.KeyDown:Connect(function(key)
	if key == "d" then
		holding = true
		print('play')
		e = 'Front'
	end
end)

mouse.KeyUp:Connect(function(key)
	if key == "d" then
		holding = false
		e = 'nil'
		print('stop')

	elseif key == "a" then
		holding = false
		e = 'nil'
		print('stop')

	end
end)

while wait() do	

	for i,v in pairs(workspace.Valves.Completed:GetChildren()) do
		if i == 5 then
			workspace.Door.Open:FireServer()
		end
	end
	if valve and holding == true then
		if e == 'Front' then
			print('Q')
			valve.CFrame = valve.CFrame * CFrame.fromEulerAnglesXYZ(0.090,0,0)

		elseif e == 'Back' then
			print('E')
			valve.CFrame = valve.CFrame * CFrame.fromEulerAnglesXYZ(-0.050,0,0)


		end
	end

	if mouse.Target then
		if script.Parent.IsUsingValve.Value == false and mouse.Target.Name == '1' or mouse.Target.Name == '2' or mouse.Target.Name == '3' or mouse.Target.Name == '4' or mouse.Target.Name == '5' or mouse.Target.Name == '6' then
			if not mouse.Target:FindFirstChild('selection') and mouse.Target.Parent == workspace.Valves and mouse.Target.Using.Value == false and script.Parent.IsUsingValve.Value == false then
				box = script.Parent.ValveUI.selection:clone()
				box.Parent = mouse.Target

				selecting = true
				box.Adornee = mouse.Target
			end
		else
			selecting = false
			if box then
				box:Destroy()
			end
		end

	end	
end

Thanks for the help! :slight_smile:

You can use ContextActionService, which is often used for mobile support controls. Settings binds for it should be fairly easy and you can even set priorities.

2 Likes

Could you possibly provide an example of how I can do this?
sorry if it may seem like a stupid question, but I’m horrible regarding scripting and other things.

Please do take a look at the link he provided. Roblox offers a full tutorial on ContextActionService

ContextActionService = game:GetService"ContextActionService" -- Service


ContextActionService:BindAction(    -- Binds an Action
    "ActionName",                   -- Name of the Bind so you can refer to it later
    function()                      -- The Function you want to fire when pressed
    end,
    true,                           -- Creates a Button for Touch Devices
    -- Below here you can add any KeyInput of InputType you like!
)

Just so you know, you may need to Move the Button’s Position around, Tho I do feel the Button like is a Bit Outdated, Here is Documentation however:

1 Like

Thank you so much, will consider doing it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.