Hey everyone rn in my game I want to be able to crouch on both pc and on Ipad etc. and I currently don’t exactly know how to convert like not convert but uh make it able for both the script is inside the textbutton
local TextButton = "CrouchButton"
local keybind = "C"
local animationId = "17667816899"
--// 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 = 8
crouching = true
animationTrack:Play()
character.HumanoidRootPart.CanCollide = false
end
end
while wait() do
if humanoid.MoveDirection.Magnitude > 0 then
animationTrack:AdjustSpeed(1)
else
animationTrack:AdjustSpeed(0)
end
end
end)