Is it Possible in Mobile that if your press a mobile button it converts it into a key?

So I am making a Stamina-Sprint script that will trigger when I click Shift, but I don’t know how to make it on mobile, my one option is making an image button with a run icon, and when it’s pressed it will convert it into shift key,
it’s like this
image

1 Like

For this you would want to use ContextActionService. Here’s the article on the dev hub for more information: ContextActionService | Documentation - Roblox Creator Hub

local key = Enum.KeyCode.LeftShift
local createbutton = true
local function sprintFunction()
--sprint stuff
end
ContextActionService:BindAction("Sprint", sprintFunction, createbutton, key)

5 Likes

If using the User Input Service and/or a custom button UI, you can just make both of them execute the same function, similarly to how it’s done with the Context Action Service, but a bit more complicated.

And where do I put this on my Gui? here’s my Gui - image button
image and the order of it
image

1 Like

Literally whatever you used to make it sprint on the key that you used, you just activate that same function when the button is held down and when it is lifted (Button1Down and Button1Up).
If you had for example startSprinting and stopSprinting, you just bind those similarly to how you bound it to work with LShift

but what if my script has “w” “a” “s” “d” bind like if you only click shift the stamina won’t lessen but if you do shift + “w” “a” “s” “d” it will lessen how do i do that on mobile?

Instead of listening for movement keys, try checking if the player is walking fast enough by reading their walking velocity. Should work for controller input too (check if a bit greater than the original walking speed)

Hmmm, so i’ll use If statement? but how to detect though what kind of variable will i do to detect if their walking fast enough?
like if walkingvelocity >= 30 then
???

something like (rootPart.Velocity * Vector3.new(1, 0, 1)).Magnitude or similar