ContextActionService:GetButton() Button Limit?

Is there a limit to how many buttons :GetButton() can be used on? On my eighth button, the function always returns nil no matter how which order I place the buttons in.

ContextActionService:BindAction("Switch", HandleAction , true, "t")
ContextActionService:SetPosition("Switch",UDim2.new(0.8,10,0.72,10-2))
ContextActionService:SetImage("Switch","rbxassetid://3645791381")
local button = ContextActionService:GetButton("Switch")
button.Size = UDim2.new(0,BUTTONSIZE-20,0,BUTTONSIZE-20)

ContextActionService:BindAction("Edit", HandleAction , true, "t")
ContextActionService:SetPosition("Edit",UDim2.new(0.8,0,0.45,-BUTTONSIZE-5))
ContextActionService:SetImage("Edit","rbxassetid://3645139947")
button = ContextActionService:GetButton("Edit")
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)

ContextActionService:BindAction("Build", HandleAction , true, "t")
ContextActionService:SetPosition("Build",UDim2.new(0.8,0,0.45,-5+BUTTONSIZE))
button = ContextActionService:GetButton("Build")
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)

ContextActionService:BindAction("Shoot", HandleAction , true, "t")
ContextActionService:SetImage("Shoot","rbxassetid://3645791517")
button = ContextActionService:GetButton("Shoot")
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)
ContextActionService:SetPosition("Shoot",UDim2.new(0.8,-BUTTONSIZE,0.45,-5))

ContextActionService:BindAction("Scope", HandleAction , true, "t")
ContextActionService:SetPosition("Scope",UDim2.new(0.8,0,0.45,-5))
ContextActionService:SetImage("Scope","rbxassetid://3645791623")
button = ContextActionService:GetButton("Scope")
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)

ContextActionService:BindAction("Reload", HandleAction , true, "t")
ContextActionService:SetPosition("Reload",UDim2.new(0.4,0,1,-BUTTONSIZE-5))
ContextActionService:SetImage("Reload","rbxassetid://3646724203")
button = ContextActionService:GetButton("Reload")
button.Size = UDim2.new(0,BUTTONSIZE * 3/4,0,BUTTONSIZE * 3/4)

ContextActionService:BindAction("ResetEdit", HandleAction , true, "t")
ContextActionService:SetPosition("ResetEdit",UDim2.new(0.8,-BUTTONSIZE,0.45,-BUTTONSIZE-5))
ContextActionService:SetImage("ResetEdit","rbxassetid://3645169990")
button = ContextActionService:GetButton("ResetEdit")
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)

ContextActionService:BindAction("Move", HandleAction , true, "t")
ContextActionService:SetPosition("Move",UDim2.new(0.8,-BUTTONSIZE,0.45,-BUTTONSIZE-5))
ContextActionService:SetImage("Move","rbxassetid://3672810912")
button = ContextActionService:GetButton("Move")
print(button)
button.Size = UDim2.new(0,BUTTONSIZE,0,BUTTONSIZE)
6 Likes

Did you try to add another button to see what happened?

I haven’t used this before, but could it be they are in the same position?

Yes, same thing happened.

@tukars I’ve tried different positions already

i wonder why your first button you make the variable like this,their really isnt a limit for :GetButton()

local button = ContextActionService:GetButton("Switch")

and the others are like this

button = ContextActionService:GetButton("Build")

Here’s a very simple snippet of code in a blank testing place. As you can see, past the 7th button, :GetButton() starts to return nil

local ContextActionService = game:GetService("ContextActionService")
 
for i = 1,10 do
	print(i)
	local function handleAction() end
	ContextActionService:BindAction("RandomName".. tostring(i),handleAction,true,"a")
	local Button = ContextActionService:GetButton("RandomName".. tostring(i))
	print(Button)
end

image

1 Like

Perhaps it has something to do with you binding the same input eight times over. All of your bindings are exactly the same except for how the buttons are handled. Try breaking things up and seeing if you can do so.

Either way, this behaviour isn’t documented from what I can see and it’d be worth hankering down to #platform-feedback:developer-hub to request documentation or receive a response about this.

2 Likes

Modified it to bind to different inputs. Still the same problem ):

local ContextActionService = game:GetService("ContextActionService")
local Inputs = {"a","b","c","d","e","f","g","h","i","j","k","l"}

for i = 1,10 do

print(i)

local function handleAction() end

ContextActionService:BindAction("RandomName".. tostring(i),handleAction,true,Inputs[i])

local Button = ContextActionService:GetButton("RandomName".. tostring(i))

print(Button)

end

Try doing the same for handleAction. You may have eight different outputs but now you have eight same functions.

If that changes nothing, you may have to rethink either
A) Your division of bindings.
B) Your division of functions.
C) Your entire input model.

Each button already has an unique handleAction function (every iteration = new handleAction function). My input model requires a lot of different buttons because there is a lot keybinds. It’s not something I can change.

1 Like

My suggestion is never rely on the touch buttons created by BindAction - aka always keep the 3rd argument to ContextActionService false. Create your own buttons using TextButton/ImageButton, and call your action handler manually according to InputBegan/InputChanged/InputEnded events firing. It’s a bit of a non-solution to your question, but I’ve always considered CAS buttons an OK temporary solution until you implement your own touch UI.

2 Likes