- What do you want to achieve? Keep it simple and clear!
I want the crouch-walking animation to play when the player is both crouching and walking ()
- What is the issue? Include screenshots / videos if possible!
While crouch-walking, the default roblox walking animation plays instead of the custom one.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried tweaking the animation’s priorities, but that did not seem to help.
Code:
local plr = game.Players.LocalPlayer
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local crouch_idle_anim = animator:LoadAnimation(script:WaitForChild("IdleCrouch"))
local TS = game:GetService("TweenService")
local crouch_walk_anim = animator:LoadAnimation(script:WaitForChild("CrouchAnimation"))
local UIS = game:GetService("UserInputService")
local IsCrouchWalking = false
local crouching_offset = Vector3.new(0,-1,-1)
local normal_offset = Vector3.new(0,0,-1)
crouch_idle_anim.Looped = true
crouch_walk_anim.Looped = true
UIS.InputBegan:Connect(function(input,gpe)
if not gpe then
if input.KeyCode == Enum.KeyCode.C then
if plr:GetAttribute("crouching") == false then
plr:SetAttribute("crouching",true)
print("crouching")
-- for i,v in pairs(char:GetChildren()) do
-- if v:IsA("BasePart") then
-- TS:Create(v,TweenInfo.new(0.5),{LocalTransparencyModifier = 1}):Play() -- Hide the player's body parts so they don't cover his camera
-- end
-- end
TS:Create(humanoid,TweenInfo.new(0.5),{CameraOffset = crouching_offset}):Play() -- lower the camera a little bit
crouch_idle_anim:Play()
else
crouch_idle_anim:Stop()
print("uncrouching")
local uncrouchTween = TS:Create(humanoid,TweenInfo.new(0.5),{CameraOffset = normal_offset}) -- recalibrate the camera when uncrouching
uncrouchTween:Play()
-- for i,v in pairs(char:GetChildren()) do
-- if v:IsA("BasePart") and v.Name ~= "Head" then
-- TS:Create(v,TweenInfo.new(0.5),{LocalTransparencyModifier = 0}):Play() -- make the player's limbs reappear (apart from the head, so it doesn't cover the camera)
-- end
-- end
uncrouchTween.Completed:Connect(function()
plr:SetAttribute("crouching",false)
end)
end
end
end
end)
plr:GetAttributeChangedSignal("crouching"):Connect(function()
if plr:GetAttribute("crouching") == true then
while task.wait() do
if humanoid.MoveDirection.magnitude > 0 then
if not IsCrouchWalking then
crouch_walk_anim:Play()
IsCrouchWalking = true
print("crouch walking")
end
else crouch_walk_anim:Stop()
end
end
end
end)
Thanks for your time