ContextActionService Buttons not appearing Correctly

  1. What do you want to achieve?
    ContextActionSevice Buttons that shows the customizations i made

  2. What is the issue?
    I made a few (6) buttons that have custom appearances, but when i test the buttons, those customizations do not appear. The buttons and their positions show correctly, but they dont show the images, transparency, etc.

  3. What solutions have you tried so far?
    I tried re-arranging and fixing a few errors, but to no avail. I’ve checked the forum for any solutions, but i wasn’t able to find any posts that matches my problem

this is a mockup of the code i wrote:

local ContextActionService = game:GetService("ContextActionService")

local function MoveRight(actionName, inputState, inputObject)
	if actionName == "MoveRight" then
		if inputState == Enum.UserInputState.Begin then
		   print("MoveRight Functioning")
	    end
	end
end


local function MoveLeft(actionName, inputState, inputObject)
	if actionName == "MoveLeft" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveLeft Functioning")
		end
	end
end

local function MoveUp(actionName, inputState, inputObject)
	if actionName == "MoveUp" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveUpLeft Functioning")
		end
	end
end

local function MoveDown(actionName, inputState, inputObject)
	if actionName == "MoveDown" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveDown Functioning")
		end
	end
end

local function ChangeView(actionName, inputState, inputObject)
	if actionName == "ViewDownSights" then
		if inputState == Enum.UserInputState.Begin then
			print("ViewDownSights Functioning")
		end
	end
end

local function FireGun(actionName, inputState, inputObject)
	if actionName == "FireGun" then
		if inputState == Enum.UserInputState.Begin then
			print("FireGun Functioning")
		end
	end
end

ContextActionService:BindAction("MoveRight", MoveRight, true, Enum.KeyCode.D)
ContextActionService:SetPosition("MoveRight", UDim2.new(-1.651, 0, 0.35, 0))

ContextActionService:BindAction("MoveLeft", MoveLeft, true, Enum.KeyCode.A)
ContextActionService:SetPosition("MoveLeft", UDim2.new(-2.151, 0, 0.35, 0))

ContextActionService:BindAction("MoveUp", MoveUp, true, Enum.KeyCode.W)
ContextActionService:SetPosition("MoveUp", UDim2.new(-1.901, 0, 0.166, 0))

ContextActionService:BindAction("MoveDown", MoveDown, true, Enum.KeyCode.S)
ContextActionService:SetPosition("MoveDown", UDim2.new(-1.901, 0, 0.512, 0))

ContextActionService:BindAction("ViewDownSights", ChangeView, true, Enum.Keycode.C)
ContextActionService:SetPosition("ViewDownSights", UDim2.new(0.531, 0, -0.05, 0))

ContextActionService:BindAction("FireGun", FireGun, true, Enum.KeyCode.F)
ContextActionService:SetPosition("FIreGun", UDim2.new(0.583, 0, -0.467, 0))



local MoveRight = ContextActionService:GetButton("MoveRight")
local MoveLeft = ContextActionService:GetButton("MoveLeft")
local MoveUp = ContextActionService:GetButton("MoveUp")
local MoveDown = ContextActionService:GetButton("MoveDown")
local ViewDownSights = ContextActionService:GetButton("ViewDownSights")
local FireGun = ContextActionService:GetButton("FireGun")


if MoveRight then

	Instance.new("UIAspectRatioConstraint").Parent = MoveRight

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveRight.Name = "RightButton"
		MoveRight.Image = "rbxassetid://7809954579"
		MoveRight.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveRight.ImageTransparency = 0.45
		
	end)
end

if MoveLeft then

	Instance.new("UIAspectRatioConstraint").Parent = MoveLeft

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveLeft.Name = "LeftButton"
		MoveLeft.Image = "rbxassetid://7809954579"
		MoveLeft.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveLeft.ImageTransparency = 0.45
		
	end)
end

if MoveUp then

	Instance.new("UIAspectRatioConstraint").Parent = MoveUp

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveUp.Name = "UpButton"
		MoveUp.Image = "rbxassetid://7809954579"
		MoveUp.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveUp.ImageTransparency = 0.45
		
	end)
end

if MoveDown then

	Instance.new("UIAspectRatioConstraint").Parent = MoveDown

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveDown.Name = "DownButton"
		MoveDown.Image = "rbxassetid://7809954579"
		MoveDown.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveDown.ImageTransparency = 0.45
		
	end)
end

if ViewDownSights then

	Instance.new("UIAspectRatioConstraint").Parent = ViewDownSights

	game:GetService("RunService").RenderStepped:Connect(function()
		ViewDownSights.Name = "AimButton"
		ViewDownSights.Image = "rbxassetid://7809955188"
		ViewDownSights.Size = UDim2.new(0.339, 0, 0.362, 0)
		ViewDownSights.ImageTransparency = 0.45

	end)
end

if FireGun then

	Instance.new("UIAspectRatioConstraint").Parent = FireGun

	game:GetService("RunService").RenderStepped:Connect(function()
		FireGun.Name = "FireButton"
		FireGun.Image = "rbxassetid://7809954579"
		FireGun.Size = UDim2.new(0.339, 0, 0.362, 0)
		FireGun.ImageTransparency = 0.45
		
	end)
end

please help!

1 Like
original

udim scale -1 is 2 or 1 screens to the left from the left side of your screen

can i see a screen shot

the positioning is fine, the problem is that

if MoveLeft then

	Instance.new("UIAspectRatioConstraint").Parent = MoveLeft

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveLeft.Name = "LeftButton"
		MoveLeft.Image = "rbxassetid://7809954579"
		MoveLeft.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveLeft.ImageTransparency = 0.45
		
	end)
end

doesn’t work for some reason

RobloxScreenShot20211111_191204562

have you tried print ing? when i tested it
i found some thing

pcall? i havent tried it yet

if you are referring to the print() function, the functions work fine as intended, just having a problem with the appearance not showing

its likely from the if statements below

yes


when i test the code i get

1

Keycode is not a valid member of “Enum” - Client - LocalScript:64
12:19:24.702 Stack Begin - Studio
12:19:24.702 Script ‘Players.Qin2007.PlayerScripts.LocalScript’, Line 64 - Studio - LocalScript:64
12:19:24.703 Stack End -

when i fix that i get

2

ContextActionService could not find the function passed in, doing nothing.

do you mean
local ContextActionService = game:GetService("ContextActionService")

local function MoveRight(actionName, inputState, inputObject)
	if actionName == "MoveRight" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveRight Functioning")
		end
	end
end


local function MoveLeft(actionName, inputState, inputObject)
	if actionName == "MoveLeft" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveLeft Functioning")
		end
	end
end

local function MoveUp(actionName, inputState, inputObject)
	if actionName == "MoveUp" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveUpLeft Functioning")
		end
	end
end

local function MoveDown(actionName, inputState, inputObject)
	if actionName == "MoveDown" then
		if inputState == Enum.UserInputState.Begin then
			print("MoveDown Functioning")
		end
	end
end

local function ChangeView(actionName, inputState, inputObject)
	if actionName == "ViewDownSights" then
		if inputState == Enum.UserInputState.Begin then
			print("ViewDownSights Functioning")
		end
	end
end

local function FireGun(actionName, inputState, inputObject)
	if actionName == "FireGun" then
		if inputState == Enum.UserInputState.Begin then
			print("FireGun Functioning")
		end
	end
end

ContextActionService:BindAction("MoveRight", MoveRight, true, Enum.KeyCode.D)
ContextActionService:SetPosition("MoveRight", UDim2.new(-1.651, 0, 0.35, 0))

ContextActionService:BindAction("MoveLeft", MoveLeft, true, Enum.KeyCode.A)
ContextActionService:SetPosition("MoveLeft", UDim2.new(-2.151, 0, 0.35, 0))

ContextActionService:BindAction("MoveUp", MoveUp, true, Enum.KeyCode.W)
ContextActionService:SetPosition("MoveUp", UDim2.new(-1.901, 0, 0.166, 0))

ContextActionService:BindAction("MoveDown", MoveDown, true, Enum.KeyCode.S)
ContextActionService:SetPosition("MoveDown", UDim2.new(-1.901, 0, 0.512, 0))

ContextActionService:BindAction("ViewDownSights", ChangeView, true, Enum.KeyCode.C)
ContextActionService:SetPosition("ViewDownSights", UDim2.new(0.531, 0, -0.05, 0))

ContextActionService:BindAction("FireGun", FireGun, true, Enum.KeyCode.F)
ContextActionService:SetPosition("FIreGun", UDim2.new(0.583, 0, -0.467, 0))



local MoveRight = ContextActionService:GetButton("MoveRight")
local MoveLeft = ContextActionService:GetButton("MoveLeft")
local MoveUp = ContextActionService:GetButton("MoveUp")
local MoveDown = ContextActionService:GetButton("MoveDown")
local ViewDownSights = ContextActionService:GetButton("ViewDownSights")
local FireGun = ContextActionService:GetButton("FireGun")


if MoveRight then

	Instance.new("UIAspectRatioConstraint").Parent = MoveRight

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveRight.Name = "RightButton"
		MoveRight.Image = "rbxassetid://7809954579"
		MoveRight.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveRight.ImageTransparency = 0.45

	end)
end

if MoveLeft then

	Instance.new("UIAspectRatioConstraint").Parent = MoveLeft

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveLeft.Name = "LeftButton"
		MoveLeft.Image = "rbxassetid://7809954579"
		MoveLeft.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveLeft.ImageTransparency = 0.45

	end)
end

if MoveUp then

	Instance.new("UIAspectRatioConstraint").Parent = MoveUp

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveUp.Name = "UpButton"
		MoveUp.Image = "rbxassetid://7809954579"
		MoveUp.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveUp.ImageTransparency = 0.45

	end)
end

if MoveDown then

	Instance.new("UIAspectRatioConstraint").Parent = MoveDown

	game:GetService("RunService").RenderStepped:Connect(function()
		MoveDown.Name = "DownButton"
		MoveDown.Image = "rbxassetid://7809954579"
		MoveDown.Size = UDim2.new(0.252, 0, 0.304, 0)
		MoveDown.ImageTransparency = 0.45

	end)
end

if ViewDownSights then

	Instance.new("UIAspectRatioConstraint").Parent = ViewDownSights

	game:GetService("RunService").RenderStepped:Connect(function()
		ViewDownSights.Name = "AimButton"
		ViewDownSights.Image = "rbxassetid://7809955188"
		ViewDownSights.Size = UDim2.new(0.339, 0, 0.362, 0)
		ViewDownSights.ImageTransparency = 0.45

	end)
end

if FireGun then

	Instance.new("UIAspectRatioConstraint").Parent = FireGun

	game:GetService("RunService").RenderStepped:Connect(function()
		FireGun.Name = "FireButton"
		FireGun.Image = "rbxassetid://7809954579"
		FireGun.Size = UDim2.new(0.339, 0, 0.362, 0)
		FireGun.ImageTransparency = 0.45

	end)
end

with

quote

RobloxScreenShot20211111_122714671
i got this by putting your code that i edited in StarterPlayerScripts

1 Like