Hello due to roblox switching up some stuff in the animations and stuff i dont know how to make the player crouch whenever i click C.
And yes i’ve looked on the internet, i could only find older versions.
Here is my script:
local animID = 16211272469
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.Character:FindFirstChild("Humanoid")
local activated = false
local UIS = game:GetService("UserInputService")
local Animator = player.Character:FindFirstChild("Humanoid").Animator
local AnimationTrack = Animator:LoadAnimation(animID)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C and activated == false then
AnimationTrack:Play()
elseif input.KeyCode == Enum.KeyCode.C and activated == true then
AnimationTrack:Stop()
end
end)
The code is correct, if you want it to be toggleable rather than holding C. What’s missing here is the activated variable not changing. When you play the animation set activated to true, when you stop the animation set it to false.
if input.KeyCode == Enum.KeyCode.C and activated == false then
AnimationTrack:Play()
activated = true
elseif input.KeyCode == Enum.KeyCode.C and activated == true then
AnimationTrack:Stop()
activated = false
end
Well the code seems indeed correct, especially since you said it doesn’t throw any errors. If it doesn’t work then there’s a few possibilities, the main one I can think of is you don’t own the animation. To check if the code is running at all, add a print inside InputBegan. If you see the text printed in the output then you know the code is really running
Don’t forgot to make it so that the UIS also has an if statement that says: if user is typing/has chat open then break - otherwise the user might accidently type c and crouch because of it.
local animID = 'rbxassetid://16211272469'
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.CharacterAdded:Wait():FindFirstChild("Humanoid")
local activated = false
local UIS = game:GetService("UserInputService")
local animation = Instance.new("Animation")
animation.AnimationId = animID
local AnimationTrack = Humanoid:LoadAnimation(animation)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
activated = not activated
print(activated)
return activated and AnimationTrack:Play() or AnimationTrack:Stop()
end
end)