So in my game, I am trying to make mobile buttons, and I did it, and they look like this:
So I tried changing the style of the button to look like the jump button. I figured out that I have to change the button image to the same Image the jump button uses, which is this image:
But it looked like this:
After some inspecting, I found out that I have to also change the ImageRectOffset and ImageRectSize to the same properties as the jump button uses, and it looked nice and cool.
But here is the problem: now when I click on the button, it resets the old image back, and I don’t know how to fix this issue or prevent it from resetting the old image.
Here is my code that creates the button:
local ContextActionService = game:GetService("ContextActionService")
local function updateImage()
local PunchButton = ContextActionService:GetButton("Punch")
if not PunchButton then return
else
PunchButton.Parent.Size = UDim2.new(0.3, 0, 0.51, 0)
PunchButton.Position = UDim2.new(1.02, -95, 0.13, -90)
PunchButton.Size = UDim2.new(0, 63, 0, 63)
PunchButton.Image = "rbxassetid://18930975093"
PunchButton.ImageRectOffset = Vector2.new(1, 140)
PunchButton.ImageRectSize = Vector2.new(144, 144)
PunchButton.ActionIcon.Position = UDim2.new(0.176, 0, 0.195, 0)
PunchButton.ActionIcon.Size = UDim2.new(0.61, 0, 0.61, 0)
PunchButton.ActionIcon.ImageTransparency = 0.4
ContextActionService:SetTitle("Punch", "")
ContextActionService:SetImage("Punch", "rbxassetid://18930905410")
end
end
function onPunchButtonPress(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
updateImage()
end
end
ContextActionService:BindAction("Punch", onPunchButtonPress, true)
updateImage()
Could someone help, please?