Yoinked some crouch script from a youtube tutorial and would like to konw: how do I make it so that if the player is crouched but isnt moving, the crouch animation will stop or freeze. How do I do it?
local uis = game:GetService(“UserInputService”)
local newanim = Instance.new(“Animation”)
newanim.AnimationId = “rbxassetid://6744589318”
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChildWhichIsA(“Humanoid”)
local animtrack = hum:LoadAnimation(newanim)
local cam = game.Workspace.CurrentCamera
local hrp = char:FindFirstChild(“HumanoidRootPart”)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
cam.CameraSubject = hrp
animtrack:Play()
hum.WalkSpeed = 8
hum.JumpPower = 0
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
cam.CameraSubject = hum
animtrack:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
end
end)
You would most likely need to check the Humanoid State. Humanoid | Roblox Creator Documentation will return the Humanoid’s current state, such as “Walking”, or “Idle” (not moving)
For easy explanation,
When the player presses C, make a debounce so that if they were to press it again, they would stop crouching.
Then in the function, listen to MoveDirection to detect whether they stopped or started to walk. Disconnect the function whenever they press it again, which would make them stop crouching.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
while wait(1) do
if not (humanoid.MoveDirection.Magnitude <= 0) then
print('you are walking and farting')
end
end