ContextActionService attempt to index nil with 'Size'

ActionService:BindAction("PressAAMobile", PressA, true, Enum.KeyCode.A)

ActionService:BindAction("PressDDMobile", PressD, true, Enum.KeyCode.D)

local PressAButton = ActionService:GetButton("PressAAMobile")

local PressDButton = ActionService:GetButton("PressDDMobile")

PressAButton.Size = UDim2.new(0,100,0,100) --line problem

PressDButton.Size = UDim2.new(0,100,0,100) 

I am making buttons on mobile with ContextActionService(Making size) but this error pops up, i tried looking at the forum but i didn’t saw any post related to what i am doing. What i am doing wrong?

1 Like

can i have some more detail, like provide a screenshot

are you running this in a local script or server

i am doing that in local script

1 Like

try server script because i think udim2 runs in server only but i could be wrong

no wait im wrong it can run in local
i think its because its probably not inside the screengui(?)

image
i mean with ContextAction buttons that pops up only in mobile

maybe you can try “Scale” ive never used contextaction before

What device are you testing the script on?

in desktop(laptop) but it shouldn’t show me(error) even when i am on desktop

Go to the “Test” section and select Devices, a list of devices should appear. Select the phone ones and try the game.

Try printing references of “PressAButton” and “PressDButton”.
After you do that, show the output.

1 Like

image

script is working but i still get error

How do you want to access the UI button reference, I don’t understand the what’s the point GetButton function invoke?

ActionService:BindAction("PressAAMobile", PressA, true, Enum.KeyCode.A)
ActionService:BindAction("PressDDMobile", PressD, true, Enum.KeyCode.D)

local PressAButton = ActionService:GetButton("PressAAMobile")
local PressDButton = ActionService:GetButton("PressDDMobile") 

script is working but i still get error

  1. I don’t understand, it works… But in what aspect? The script does its job but the size is what doesn’t work?
  2. Maybe it didn’t work because you didn’t test on a touch device, I think this will help you:
    https://devforum.roblox.com/t/contextactionservicegetbutton-never-returns-if-button-doesnt-exist/20017/19

ActionService:GetButton("PressAAMobile") is returning nil, so it might not have loaded? I’m not entirely sure how ContextActionService buttons work but try adding atask.wait(5) and see if it works then