Can I have multiple ContextActionService mobile buttons?

  1. What do you want to achieve?
    Hi! I ask a lot of questions. Is it possible to have multiple ContextActionService buttons at once?
  2. What is the issue? I have two buttons so far (I’m trying to add a few more if needed) for emotes, since I can’t figure out how to use GUI buttons for emotes like laying and different types of sitting.

I’m pretty sure only one button works at once, since when I press my buttons, it does this:

tango sit problem

  1. What solutions have you tried so far? I’ve tried to enable both scripts (When I do sit 1, it temporarily disables sit 2 until sit 1 is toggled off) but it still only has one button.

Possible solutions:

  • If I could figure out how to use this controls frame with mobile, that would be much easier since my players would be able to press on both mobile and desktop versions.
    image
    I originally didn’t want to do ContextActionService at all because I didn’t understand it, and honestly I was a little intimidated. This one game, Farm World, has GUI buttons that work on mobile, I just can’t seem to figure out how to do it.
  • Maybe I can have a mobile-only GUI button that changes which emote is loaded into the one button.
  • It might be possible for me to do a radial menu like Creatures of Sonaria has.

But regardless, thanks for reading and I hope someone can answer my original question, even if they don’t have a solid solution.

It looks like your only pressing one button in the gif you showed us up there

There’s two different buttons, but when I press the lower one (sit 2) the top one (sit 1) appears and the first disappears. Sorry that wasn’t clear! I think it should look like this if both were up. I did this picture in a picture-editing program, both buttons aren’t onscreen at the same time.

image

Well to answer your question, yes you can have multiple ConextActionService mobile buttons; you must be doing something wrong; could we see your code and do you have any errors in the output

Sweet! My code is taken from a few different tutorials, plus solutions I’ve found on here.

Sit 1:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local sitting = false
local running = false

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://6243668915"

local playAnim = humanoid:LoadAnimation(anim)

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin and sitting == false and running == false then
		script.Parent.Chairsit.Disabled = true
		playAnim:Play()
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 0
		sitting = true
		running = true
		humanoid.CameraOffset = Vector3.new(0,0,0)
		wait()
		script.Parent.Sprint.Disabled = true
	elseif userInputState == Enum.UserInputState.Begin and sitting == true and running == true then
		wait(1)
		playAnim:Stop()
		humanoid.WalkSpeed = 10
		humanoid.JumpPower = 75
		sitting = false
		running = false
		humanoid.CameraOffset = Vector3.new(0,0,0)
		script.Parent.Sprint.Disabled = false
		end
end

game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.R)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-1,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://6264154092")

Sit 2:

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://6245918988"

local playAnim = humanoid:LoadAnimation(anim)

function onKeyPress(actionName, userInputState, inputObject)
	if  userInputState == Enum.UserInputState.Begin and sitting == false and running == false then
		script.Parent.Floorsit.Disabled = true
		playAnim:Play()
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 0
		sitting = true
		running = true
		humanoid.CameraOffset = Vector3.new(0,0,0)
		wait()
		script.Parent.Sprint.Disabled = true and sitting == false
		elseif userInputState == Enum.UserInputState.Begin and sitting == true and running == true then
		script.Parent.Floorsit.Disabled = false
		playAnim:Stop()
		humanoid.WalkSpeed = 10
		humanoid.JumpPower = 75
		sitting = false
		running = false
		humanoid.CameraOffset = Vector3.new(0,0,0)
		script.Parent.Sprint.Disabled = false
		end
end

game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.T)
game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0))
game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://6264143607")

Edit: There aren’t any errors, and both emotes work at least once.

1 Like

OH!

The last lines of code that say “keyPressSpecialName” need to be changed to something else. I feel silly now. Thanks for trying!