Strange Behavior when Attempting to Move ContextActionService GuiButton

Hello. I am running into an issue with ContextActionService, specifically the ability for it to create GuiButtons

I create a button, and then I attempt to reposition is using :SetPosition(). However, this appears to fail to move the button.
I assume this is because the button is not yet created (which is its own can of worms), but if I use :SetTitle(), the method call works, and the string passed shows up.

	ContextActionService:BindAction("VIBKeyboardForward", onForwardPressed, true, Enum.KeyCode.W)
	ContextActionService:SetTitle("VIBKeyboardForward", "Hello")
	ContextActionService:SetPosition("VIBKeyboardForward",UDim2.new(.3,0,.3,0))

image
(The title is set, but the position is not)

One thing that seems to work is to wait an amount of time (using task.wait() or task.delay(). One second works fine), however, waiting an arbitrary amount of time for things to be ready, and then assuming them to be ready sounds like a bad practice.
The ideal is an event of some sort that fires when the GuiButton is ready, but I could not find anything about that.

	ContextActionService:BindAction("VIBKeyboardForward", onForwardPressed, true, Enum.KeyCode.W)
	task.wait(1)
	ContextActionService:SetTitle("VIBKeyboardForward", "Hello")
	ContextActionService:SetPosition("VIBKeyboardForward",UDim2.new(.3,0,.3,0))

image
(Now both the title and position are set)

I really don’t understand what is going on here, and any help would be greatly appreciated.

Put your script into StarterGui and the problem should dissapear. I have no idea why this is happening when having it in PlayerScripts.

Sorry for the late reply.

That does work. Strange…

Thank you!

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