Need help to make mobile suport

I found a crouch script on youtube but dont have mobile support

(Im not good at scripting)

i want to add a gui button when player press the button the character crouch

can someone help me?

script

"

local ContextActionService = game:GetService(“ContextActionService”);
local RunService = game:GetService(“RunService”);
local TweenService = game:GetService(“TweenService”);

local GeometricPlane = Vector3.new(1, 0, 1);
local UpVector = Vector3.new(0, 1, 0);

local States = {
[“Crouching”] = Instance.new(“BoolValue”);
};

local player = game.Players.LocalPlayer;
local character = player.Character or player.CharacterAdded:Wait();
local Humanoid = character:WaitForChild(“Humanoid”) :: Humanoid;
local Animator = Humanoid:WaitForChild(“Animator”) :: Animator;
local HumanoidRootPart = Humanoid.RootPart :: BasePart;

local CurrentCamera = workspace.CurrentCamera;

local AnimationFolder = script:WaitForChild(“Animations”);
local Animations = {} :: {
[string]: AnimationTrack
};

local CrouchConnection: RBXScriptConnection = nil;

local range = 2;
local WalkSpeed = Humanoid.WalkSpeed;
local CrouchSpeed = WalkSpeed/2;

local CameraCrouchPosition = Vector3.new(0,-2,0);
local CameraStandPosition = Vector3.new(0,0,0);

local CrouchFOV = 60;
local StandFOV = 70;

local CameraCrouchPositionTI = TweenInfo.new(1, Enum.EasingStyle.Cubic);
local CameraStandPositionTI = TweenInfo.new(1, Enum.EasingStyle.Cubic);

local FOVCrouchTI = TweenInfo.new(.5, Enum.EasingStyle.Cubic);
local FOVStandTI = TweenInfo.new(.5, Enum.EasingStyle.Cubic);

local Keybind = Enum.KeyCode.LeftControl;

for i: number, v: Animation in ipairs(AnimationFolder:GetChildren()) do
if v:IsA(“Animation”) then
Animations[v.Name] = Animator:LoadAnimation(v);
Animations[v.Name].Priority = Enum.AnimationPriority.Action2;
end;
end;

function isBelowAnObject(character: Model, range: number): (boolean?)
local RParams = RaycastParams.new();
RParams.FilterType = Enum.RaycastFilterType.Exclude;
RParams.IgnoreWater = true;
RParams.RespectCanCollide = true;
RParams.FilterDescendantsInstances = {character};

if (result) then
	if (result.Instance ~= nil) then
		return (true);
	end;
end;

return (false);

end;

function Crouch(ActionName: string, InputState: Enum.UserInputState, InputObject: InputObject): () if not (script:FindFirstChild(“By GalladeR475”)) then warn(“Credits not given to GalladeR475”); return; elseif (not script:FindFirstChild(“By GalladeR475”).Value) then warn(“Credits not given to GalladeR475”); return; end;
if (ActionName == “CrouchPlayer”) then
if (InputState == Enum.UserInputState.Begin) then
States[“Crouching”].Value = true;
if (CrouchConnection) then
CrouchConnection:Disconnect();
end;
end;
if (InputState == Enum.UserInputState.End) then
CrouchConnection = RunService.Heartbeat:Connect(function(dt: number)
if (not isBelowAnObject(character, range)) then
States[“Crouching”].Value = nil;
end;
end);
end;
end;
end;

States[“Crouching”]:GetPropertyChangedSignal(“Value”):Connect(function()
local Value = States[“Crouching”].Value;

RunService.Heartbeat:Connect(function(dt: number)
	if (Humanoid.MoveDirection.Magnitude > 0) then
		Animations["Crouch"]:AdjustSpeed(1);
	else
		Animations["Crouch"]:AdjustSpeed(0);
	end;
end);

if (Value) then
	Animations["Crouch"]:Play();
	Humanoid.WalkSpeed = CrouchSpeed;
	TweenService:Create(Humanoid, CameraCrouchPositionTI, {CameraOffset = CameraCrouchPosition}):Play();
	TweenService:Create(CurrentCamera, FOVCrouchTI, {FieldOfView = CrouchFOV}):Play();
else
	Animations["Crouch"]:Stop()
	Humanoid.WalkSpeed = WalkSpeed;
	TweenService:Create(Humanoid, CameraStandPositionTI, {CameraOffset = CameraStandPosition}):Play();
	TweenService:Create(CurrentCamera, FOVStandTI, {FieldOfView = StandFOV}):Play();
end;

end);

ContextActionService:BindAction(“CrouchPlayer”, Crouch, false, Keybind);

"

Hello KingsmanRicsike,
i found a roblox model that even support mobile support, anyway here is the link of the model: https://create.roblox.com/store/asset/8944594530/Kjydlonges-CrouchMobile-support?externalSource=www

i hope it can be useful to you

Thanks

1 Like