Why is my animation not playing
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("combat")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Cooldown = false
local Combo = 0
local Animation1 = script:WaitForChild("Animation1")
local Animation2 = script:WaitForChild("Animation2")
local Animation3 = script:WaitForChild("Animation3")
local Animation4 = script:WaitForChild("Animation4")
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E and not Cooldown then
Cooldown = true
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local animator = humanoid:FindFirstChildOfClass("Animator") or humanoid:WaitForChild("Animator")
for _, track in pairs(animator:GetPlayingAnimationTracks()) do
track:Stop()
end
local animationToPlay
if Combo == 0 then
animationToPlay = animator:LoadAnimation(Animation1)
elseif Combo == 1 then
animationToPlay = animator:LoadAnimation(Animation2)
elseif Combo == 2 then
animationToPlay = animator:LoadAnimation(Animation3)
elseif Combo == 3 then
animationToPlay = animator:LoadAnimation(Animation4)
end
if animationToPlay then
animationToPlay:Play()
else
warn("Animation failed to load.")
end
Remote:FireServer(hrp.CFrame, hrp)
Combo += 1
if Combo > 3 then
Combo = 0
end
task.delay(1, function()
Combo = 0
end)
task.wait(0.2)
Cooldown = false
end
end)
** You are now Level 1! **