Mobile buttons aren't changed as supposed to be according to their script

Hi,
I’m trying to make mobile buttons for a game of mine, and I’m setting up a move set for a certain weapon.

So far, I have 5 working buttons in this specific script (Moves E, R, T, Y, and Q) which all are positioned with UDim2 correctly and have their images that I’d set. The problem came up with the last 4 buttons, which are formatted in the script the exact same way as the buttons made prior, yet are stuck stacked at the position {0, 0},{0, 0} without the asset icon I’d given them.

What it looks like:

I have tried positioning the buttons in various different locations, to no avail. The only topic I could find similar to this was this post in August, and it doesn’t seem like it was solved.
My mobile buttons won’t move to the place I script them to go

The code in the block below displays what the broken buttons are supposed to do, yet it seems that the SetPoisition and SetImage are being ignored. The script for these buttons was copied directly from the working buttons prior to it.

		
	local fmove = contextActionService:BindAction("fmove", handleAction, true, Enum.KeyCode.F, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("fmove",UDim2.new(0.078, -300, 0.2, -25))
	contextActionService:SetImage("fmove","http://www.roblox.com/asset/?id=196377547")

	local zmove = contextActionService:BindAction("zmove", handleAction, true, Enum.KeyCode.Z, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("zmove",UDim2.new(0.07, 30, 0.2, 110))
	contextActionService:SetImage("zmove","http://www.roblox.com/asset/?id=2190354994")

	local nmove = contextActionService:BindAction("nmove", handleAction, true, Enum.KeyCode.N, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("nmove",UDim2.new(0.07, -70, 0.2, 110))
	contextActionService:SetImage("nmove","http://www.roblox.com/asset/?id=2311956965")

	local gmove = contextActionService:BindAction("gmove", handleAction, true, Enum.KeyCode.G, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("gmove",UDim2.new(0, -20, 0, 110))
	contextActionService:SetImage("gmove","http://www.roblox.com/asset/?id=4675182940")

I do not have much experience with scripting buttons like this, so this could very easily just be a newbie mistake on my part, but I’d still appreciate any help possible.

1 Like

I found a solution, if you have a script like these in the starter pack you should place the script in startergui so you can move them, it wouldnt change anything about the script since you used contextactionservice

2 Likes

This is what you need to make the buttons tidy

Adapted from the same page

A more reliable way to position custom buttons is in direct relation to the jump button. The following code fetches the position of the jump button and creates a placeholder ImageButton above it:

This is your picture of the Button fmove

-- Get reference to player's jump button
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local TouchGui = PlayerGui:WaitForChild("TouchGui")
local TouchControlFrame = TouchGui:WaitForChild("TouchControlFrame")
local JumpButton = TouchControlFrame:WaitForChild("JumpButton")
   
 -- Get absolute size and position of button
local absSizeX, absSizeY = JumpButton.AbsoluteSize.X, JumpButton.AbsoluteSize.Y
local absPositionX, absPositionY = JumpButton.AbsolutePosition.X, JumpButton.AbsolutePosition.Y

-- Create new button above jump button
local customButton = Instance.new("ImageButton")
customButton.Parent = ScreenGui
customButton.AnchorPoint = Vector2.new(0.5, 1)
customButton.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton.Position = UDim2.new(0, absPositionX+(absSizeX/2), 0, absPositionY-20)
customButton.Image = "http://www.roblox.com/asset/?id=196377547"
customButton.BackgroundTransparency = 1

Button fmove

It does the same for all buttons

3 Likes

Good to know you found the solution, I’d do this, except the script must be in the player’s character or it’d break according to the weapon system.

1 Like

Just tried this, setting the position according to the jump button, except the problem is still persisting, the four button moves F, N, G, and Z won’t move or change at all.

Here's the entire block including the working buttons.
	local qmove = contextActionService:BindAction("qmove", handleAction, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("qmove",UDim2.new(0, -330,0, 105))
	contextActionService:SetImage("qmove","http://www.roblox.com/asset/?id=2581609886")

	local emove = contextActionService:BindAction("emove", handleAction, true, Enum.KeyCode.E, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("emove",UDim2.new(0.078, -400, 0.2, -25))
	contextActionService:SetImage("emove","http://www.roblox.com/asset/?id=241837157")

	local rmove = contextActionService:BindAction("rmove", handleAction, true, Enum.KeyCode.R, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("rmove",UDim2.new(0.078, -350, 0.2, -25))
	contextActionService:SetImage("rmove","http://www.roblox.com/asset/?id=4522567088")

	local tmove = contextActionService:BindAction("tmove", handleAction, true, Enum.KeyCode.T, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("tmove",UDim2.new(0, -305,0.2, 25))
	contextActionService:SetImage("tmove","http://www.roblox.com/asset/?id=530918460")

	local ymove = contextActionService:BindAction("ymove", handleAction, true, Enum.KeyCode.Y, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("ymove",UDim2.new(0.078, -375, 0.2, 25))
	contextActionService:SetImage("ymove","http://www.roblox.com/asset/?id=2938212006")
	
	-- All the buttons above this comment are working, and the buttons below are not.
	
	local fmove = contextActionService:BindAction("fmove", handleAction, true, Enum.KeyCode.F, Enum.KeyCode.ButtonY)
	fmove.Name = "fmove"
	contextActionService:SetPosition("fmove",UDim2.new(0.078, -300, 0.2, -25))
	contextActionService:SetImage("fmove","http://www.roblox.com/asset/?id=196377547")
	--contextActionService:SetPosition("fmove",UDim2.new(0, absPositionX+(absSizeX/2), 0, absPositionY-20))

	local zmove = contextActionService:BindAction("zmove", handleAction, true, Enum.KeyCode.Z, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("zmove",UDim2.new(0.07, 30, 0.2, 110))
	contextActionService:SetImage("zmove","http://www.roblox.com/asset/?id=2190354994")

	local nmove = contextActionService:BindAction("nmove", handleAction, true, Enum.KeyCode.N, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("nmove",UDim2.new(0.07, -70, 0.2, 110))
	contextActionService:SetImage("nmove","http://www.roblox.com/asset/?id=2311956965")

	local gmove = contextActionService:BindAction("gmove", handleAction, true, Enum.KeyCode.G, Enum.KeyCode.ButtonY)
	contextActionService:SetPosition("gmove",UDim2.new(0, -20, 0, 110))
	contextActionService:SetImage("gmove","http://www.roblox.com/asset/?id=4675182940")```

As you can see on button “fmove”, I had tried setting the position relative to the jump button but this yielded no result. I’m unsure as to if the buttons are just broken due to a glitch in Studio or if it’s something on my part, because it’s odd how they wouldn’t change like the others did.

1 Like

I do not speak English

the translation is unclear

This code may help you with what you want to do

Don’t change anything in the code, just copy the code

This code when placed inside a LocalScript in StarterGui in ScreenGui

-- Get reference to player's jump button
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local TouchGui = PlayerGui:WaitForChild("TouchGui")
local TouchControlFrame = TouchGui:WaitForChild("TouchControlFrame")
local JumpButton = TouchControlFrame:WaitForChild("JumpButton")

-- Get absolute size and position of button
local absSizeX, absSizeY = JumpButton.AbsoluteSize.X, JumpButton.AbsoluteSize.Y
local absPositionX, absPositionY = JumpButton.AbsolutePosition.X, JumpButton.AbsolutePosition.Y

-- Create new button above jump button
local customButton = Instance.new("ImageButton")
customButton.Parent = ScreenGui
customButton.AnchorPoint = Vector2.new(0.5, 1)
customButton.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton.Position = UDim2.new(0, absPositionX+(absSizeX/2), 0, absPositionY-20)
customButton.BackgroundTransparency = 0

local customButton1 = Instance.new("ImageButton")
customButton1.Parent = ScreenGui
customButton1.AnchorPoint = Vector2.new(0.5, 1)
customButton1.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton1.Position = UDim2.new(0, absPositionX-(absSizeX/2), 0, absPositionY-20)
customButton1.BackgroundTransparency = 0

local customButton2 = Instance.new("ImageButton")
customButton2.Parent = ScreenGui
customButton2.AnchorPoint = Vector2.new(0.5, 1)
customButton2.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton2.Position = UDim2.new(0, absPositionX+(absSizeX/2), 0, absPositionY-100)
customButton2.BackgroundTransparency = 0

local customButton3 = Instance.new("ImageButton")
customButton3.Parent = ScreenGui
customButton3.AnchorPoint = Vector2.new(0.5, 1)
customButton3.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton3.Position = UDim2.new(0, absPositionX-(absSizeX/2), 0, absPositionY-100)
customButton3.BackgroundTransparency = 0

local customButton4 = Instance.new("ImageButton")
customButton4.Parent = ScreenGui
customButton4.AnchorPoint = Vector2.new(0.5, 1)
customButton4.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton4.Position = UDim2.new(0, absPositionX-(absSizeX/2), 0, absPositionY+60)
customButton4.BackgroundTransparency = 0

local customButton5 = Instance.new("ImageButton")
customButton5.Parent = ScreenGui
customButton5.AnchorPoint = Vector2.new(0.5, 1)
customButton5.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton5.Position = UDim2.new(0, absPositionX-(absSizeX*1.5), 0, absPositionY+60)
customButton5.BackgroundTransparency = 0

local customButton6 = Instance.new("ImageButton")
customButton6.Parent = ScreenGui
customButton6.AnchorPoint = Vector2.new(0.5, 1)
customButton6.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton6.Position = UDim2.new(0, absPositionX-(absSizeX*2.5), 0, absPositionY+60)
customButton6.BackgroundTransparency = 0

local customButton7 = Instance.new("ImageButton")
customButton7.Parent = ScreenGui
customButton7.AnchorPoint = Vector2.new(0.5, 1)
customButton7.Size = UDim2.new(0, absSizeX*0.8, 0, absSizeY*0.8)
customButton7.Position = UDim2.new(0, absPositionX-(absSizeX*3.5), 0, absPositionY+60)
customButton7.BackgroundTransparency = 0

The result is the buttons arranged as pictured

buttons arranged

2 Likes

If your weapon system runs off of a fire server just use your default script (not local) slap it into starter gui and keep the local script and fireserver in character/player scripts and change the fireserver position in the script?