Animation GUI not working on mobile, only on PC

Hello,

So, I’ve been working on a project for awhile and I’m in the stage of mobile support.

A snippet of the code that handles input:

local button = script.Parent.SampleButton

local current = nil

do
	local y = 0
	for dance, id in pairs(Dances) do
		local _button = button:Clone()
		_button.Name = dance; _button.Text = dance
		y += .125; button.Position = UDim2.fromScale(0, y)
		_button.Parent = script.Parent
		
		local animation = Instance.new("Animation")		
		animation.AnimationId = "rbxassetid://".. tostring(id)
		local _anim = animator:LoadAnimation(animation)
		
		Dances[dance] = _anim
		
		_button.Activated:Connect(function()
			if (current) then
				Dances[current]:Stop()
				if (current == _button.Text) then current = nil; return; end
			end
			Dances[_button.Text]:Play()
			current = _button.Text
		end)
	end
	button:Destroy()
end

It works on PC perfectly fine, but on mobile it doesn’t. The scrolling frame works perfectly fine but i’m still unable to actually click on anything to make it fire an animation.

Originally I had the .MouseButton1Click event, and it didn’t really make much of a difference between which event I had. I’m not really sure what’s going on.
Example:

Could you try using MouseButton1Down? There’s been some strange instances that some GUIButtons don’t work in a ScrollingFrame:

1 Like

Yeah, I’ll give it a shot.

EDIT: Oh wow that actually worked!

Yeah ROBLOX needs to update their API References w h e e z e

That’s so dumb, holy. T.T

I’m still new to LUA and everything. Do you also know anything about binding mobile controls to keys like WASD // Movement on stuff like Skateboards?

Yeah, you’d need ContextActionService which can bind mobile buttons for certain functions to work

Funny thing is that there is an API Reference for this:

I’ve stared at the document for so long, but nothing registered for me with accomplishing what I want. Maybe I’m just smooth brain.

Well, maybe we can dumb it down a bit:

The BindAction function can be used to connect our own custom actions we want to register (Whether it be eating a Cookie, riding a Skateboard, etc)

There are a couple of requirements we need to pass in though

  • An Action Name, we can name it whatever we want

  • A function that will handle the changes made when the Action is called

  • A bool (Or just true/false) if we want to enable a Mobile Button

  • A tuple (Or amount) of keybinds we want to assign that specific action on

Say I have this:

local CAS = game:GetService("ContextActionService")

local function Laugh()
    print("LOL XDDDDDDDDDDDDDDDDDDDDDD")
end

CAS:BindAction("Laugh Out Loud", Laugh, true, Enum.KeyCode.A)

We’re first setting our action name, connecting our function, creating a mobile button, then last assigning a keybind to it

Yeah scripting is definitely not confusing

Hmm. I think I have been over thinking this, I was going through the scripts inside the skateboard and was trying to figure out where the movement was being handled, but I guess it was just being handled through the platform(?)

Would I just need to write a whole new function just rebinding things to W,A,S,D for steering or whatever?

You could just call as much keybinds as you’d want when using the BindAction function, HECK I CAN EVEN DO THIS:

CAS:BindAction("Laugh Out Loud", Laugh, true, Enum.KeyCode.A, Enum.KeyCode.B, Enum.KeyCode.D, Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.T, Enum.KeyCode.H, Enum.KeyCode.Q, Enum.KeyCode.F, Enum.KeyCode.N)

And it’d still connect to everything

My problem is mostly figuring out what goes into the function block like what constitutes from moving up on the thumbpad to Up/Down/Left/Right and how it would translate into something that works with vehicles, or in this case a skateboard? :o

You’d probably need to get the GetMoveVector function of the ControlModule

It’s a bit complicated, but that’s prob the way you could do it

Well, this is daunting to look at and wrap my head around. I just found the function that handles all the keypress for movement:

function Equipped(humanoid, controller)
	trickdb = false
	grab = false
	Controller = controller
	Humanoid = humanoid
	Character = Humanoid.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	PlayerGui = Player:FindFirstChild("PlayerGui")
	Torso = Character:FindFirstChild("HumanoidRootPart")
	
	script.Parent.Parent.Parent = Character
	if not CheckIfAlive() then
		return
	end
	for i, v in pairs({KeyDownConnection, KeyUpConnection}) do
		if v then
			v:disconnect()
		end
	end
	for i, v in pairs({Animations.R6, Animations.R15, Sounds}) do
		for ii, vv in pairs(v) do
			if vv:IsA("Animation") then
				ContentProvider:Preload(vv.AnimationId)
			elseif vv:IsA("Sound") then
				ContentProvider:Preload(vv.SoundId)
			end
		end
	end
	KeyDownConnection = UserInputService.InputBegan:connect(function(InputObject)
		if InputObject.UserInputState == Enum.UserInputState.Begin then
			InvokeServer("KeyPress", {Down = true, Key = InputObject.KeyCode})
		end
	end)
	KeyUpConnection = UserInputService.InputEnded:connect(function(InputObject)
		if InputObject.UserInputState == Enum.UserInputState.End then
			InvokeServer("KeyPress", {Down = false, Key = InputObject.KeyCode})
		end
	end)
	for i, v in  pairs(Board:GetChildren()) do
		if v:IsA("BodyThrust") or v:IsA("BodyGyro") then
			v:Destroy()
		end
	end
	SkateboardEquipped = true
	bf = Instance.new("BodyForce",Board)
	bf.Force = Vector3.new(0,400,0)
	MakeOllieThrust()
	MakeGyro()
	Controller.AxisChanged:connect(AxisChanged)
	Board.MoveStateChanged:connect(MoveStateChanged)
	Controller:BindButton(Enum.Button.Jump, "")
	Controller.ButtonChanged:connect(ButtonChanged)
	SetAnimation("Play", {Animation = GetAnimation("CoastingPose")})
	InvokeServer("Equipped", Character)
end

I feel like the entirety of how this was done is completely deprecated now, but I probably could just work with this to translate into mobile friendly?

I mean you could just use it as a reference, I don’t know much about how CAS works so this is probably the best I can do

1 Like

Alright, ty for the help! Even though this post got completely derailed and I probably should’ve just made an entirely new topic.

1 Like