Context action service question

I am trying to convert my game to mobile. On computer, the player can run using the keyboard and click to shoot. When I’m trying to convert it to mobile, the character shoots whenever the player uses the joystick GUI to move. How can I separate it so that touching the screen to move and touching the screen to shoot don’t fire the same thing.

1 Like

You can make it into 2 different action and also bind the action correctly helps

1 Like

You should check to see what the player’s device type is with User Input Service, and if their on mobile, add a gui button that will activate the shooting instead.

1 Like

I’d actually recommend UIS > CAS for this particular scenario. You’d be able to separate the inputs through something along the lines of: if (input is click) or (input is tap) or (input is right trigger) then fire the weapon.

That written as code using UIS looks something like this:

game:GetService("UserInputService").InputBegan:Connect(function(input,gameProcessed)
	if not gameProcessed then
		if input.UserInputState == Enum.UserInputState.Begin then
			local inputType,keyCode = input.UserInputType,input.KeyCode
			if inputType == Enum.UserInputType.MouseButton1 
			or inputType == Enum.UserInputType.Touch
			or keyCode == Enum.KeyCode.ButtonR2 then
				-- fire the weapon
			end
		end
	end
end)
1 Like

you can create a new button for the CAS I refer to

local CAS = game:GetService("ContextActionService")

local function Context(Action,inputstate,inputobject)
    if Action == "Shooting" and inputstate = Enum.InputState.Begin then
          --Do something
    end
end

CAS:BindAction("Shooting",Context,true,Enum.Keycode.R)

@RiccoMiller