RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"if C pressed and the player walkspeed is 16 dont make crouch = true the crouch functions"
-- server script local NormalWS = 16 local CrouchS = 6 local AnimationID = "rbxassetid://14376625517" local cas = game:GetService("ContextActionService") local CrouchKeyCode = Enum.KeyCode.C local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local Humanoid = char:WaitForChild("Humanoid") local CrouchAnim = Instance.new("Animation") CrouchAnim.AnimationId = AnimationID local CrouchAnimm = Humanoid:LoadAnimation(CrouchAnim) CrouchAnimm.Looped = true local Camera = game.Workspace.CurrentCamera local TweenService = game:GetService("TweenService") local UIS = game:GetService("UserInputService") local Crouching = false CrouchAnimm:AdjustSpeed(1) local function onCrouch(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then if Crouching then Crouching = false Humanoid.WalkSpeed = NormalWS Humanoid.JumpPower = 50 Humanoid.JumpHeight = 7.2 CrouchAnimm:Stop() elseif Humanoid.WalkSpeed ~= NormalWS then Crouching = true Humanoid.WalkSpeed = CrouchS Humanoid.JumpPower = 0 Humanoid.JumpHeight = 0 CrouchAnimm:Play() end end end cas:BindAction("Crouch", onCrouch, true, Enum.KeyCode.C) cas:SetImage("Crouch", "rbxassetid://5149449514") cas:SetPosition("Crouch", UDim2.new(0.382, 0, 0.088, 0)) Humanoid.Running:Connect(function(speed) if Crouching and speed == 0 then CrouchAnimm:AdjustSpeed(0) elseif speed > 0 then CrouchAnimm:AdjustSpeed(1) end end)