Keybinds for different devices for a crawl mechanic

So, I found a perfect crawl script but it turns out it only supports PC. I wanted to make it compatible for consoles and phones/tablets. So I took a try at making it for consoles, I tried the LT button and tested it out, it obviously did not work. So I looked for any solutions on here and didn’t find any. I highly doubt I was going to be able to make it for mobile devices, so can anyone help me get this script compatible for consoles and mobile devices?

--// Configuration
local keybind = "C"
local Keybind = "ButtonLT"
local animationId = 13533049168 --> Replace the number with your animation ID!
  

--// Variables
local UserInputService = game:GetService("UserInputService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://' .. animationId

local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action

local crouching = false


--// Functions
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.KeyCode == Enum.KeyCode[keybind] then
		if crouching then
			humanoid.WalkSpeed = 16
			crouching = false
			animationTrack:Stop()
			character.HumanoidRootPart.CanCollide =  true
		else
			humanoid.WalkSpeed = 7
			crouching = true
			animationTrack:Play()
			character.HumanoidRootPart.CanCollide =  false
		end
	end
end)

havent tested it but this should work

--// Configuration
local Keybinds = {
	Enum.KeyCode.C,
	Enum.KeyCode.ButtonL2
}

local animationId = 13533049168 --> Replace the number with your animation ID!


--// Variables
local UserInputService = game:GetService("UserInputService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://' .. animationId

local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action

local crouching = false


--// Functions
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if table.find(Keybinds, input.KeyCode) then
		if crouching then
			humanoid.WalkSpeed = 16
			crouching = false
			animationTrack:Stop()
			character.HumanoidRootPart.CanCollide =  true
		else
			humanoid.WalkSpeed = 7
			crouching = true
			animationTrack:Play()
			character.HumanoidRootPart.CanCollide =  false
		end
	end
end)
1 Like

It actually sort of works, but there is no button to crouch on mobile. but it works for Xbox!

you can use ContextActionService or TopBarPlus to make the button for mobile
or you can also make your own GUI

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.