Currently I’ve been trying for a couple of hours now to make an Idle Crouch + Walking Crouch script where when the player is Idle it will perform a different animation from when they are moving while in the crouch position.
I have achieved making the player able to perform the crouch animation but don’t understand how to use Humanoid.Running and Humanoid.MoveDirection and also where I should do this within the script.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local Animation = Instance.new("Animation")
Animation.Parent = player.Character
local Animate
local debounce = false
UIS.InputBegan:Connect(function(Input)
if Humanoid.MoveDirection.Magnitude < 0 then
Animation.AnimationId = "rbxassetid://6299885626"
else
Animation.AnimationId = "rbxassetid://0"
if Input.KeyCode == Enum.KeyCode.LeftControl then
if not debounce then
debounce = true
Animate = Humanoid:LoadAnimation(Animation)
Animate:Play()
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 9
Humanoid.JumpPower = 0
else
Animate:Stop()
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
debounce = false
end
end
end
end)
Edit, so I worked out how to Loop the change but will me looping the Idle check in the background effect the performance of my game?
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local Animation = Instance.new("Animation")
Animation.Parent = player.Character
local Animate
local debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.C then
if not debounce then
debounce = true
Animate = Humanoid:LoadAnimation(Animation)
Animate:Play()
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 9
Humanoid.JumpPower = 0
else
Animate:Stop()
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
debounce = false
end
end
end)
while true do
wait(0.1)
if Humanoid.MoveDirection.Magnitude == 0 then
Animation.AnimationId = "rbxassetid://8365991997"
print("Idle")
else
Animation.AnimationId = "rbxassetid://8365991997"
print("Walking")
end
end