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:
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
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?
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
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?