-
What do you want to achieve?
I want my character to turn on animations when I click the C key, but the animation doesn’t work -
What is the issue?
The problem is that in the animation editor the animation works normally, but when I click the C button the animation does not work and the character takes an exclamation point pose
After Click C:
Code:
local TweenService = game:GetService("TweenService")
local Humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local HumanoidRootPart = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local CrouchAnimation = script.CrouchAnimation
local CrouchTrack = Humanoid:LoadAnimation(CrouchAnimation)
local CameraInfo = TweenInfo.new(
0.3,
Enum.EasingStyle.Quint,
Enum.EasingDirection.Out,
0,
false,
0
)
local CrouchedGoal = {CameraOffset = Vector3.new(0,-1.75,0)}
local UncrouchedGoal = {CameraOffset = Vector3.new(0,0,0)}
local CrouchedTween = TweenService:Create(Humanoid, CameraInfo, CrouchedGoal)
local UncrouchedTween = TweenService:Create(Humanoid, CameraInfo, UncrouchedGoal)
local inCrouch = false
local function Crouch()
if inCrouch == false then
inCrouch = true
CrouchedTween:Play()
Humanoid.WalkSpeed = 8
CrouchTrack:Play()
HumanoidRootPart.CanCollide = false
else
inCrouch = false
UncrouchedTween:Play()
Humanoid.WalkSpeed = 16
CrouchTrack:Stop()
HumanoidRootPart.CanCollide = true
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
Crouch()
end
end)
-
What solutions have you tried so far?
Currently I can’t find why this is happening and that’s why I’m writing