#"LoadAnimation requires an Animation object" error

1 messages · Page 1 of 1 (latest)

vivid holly
#
local LocalPlayer = game:GetService("Players").LocalPlayer
local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls()

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local WalkSpeed = Humanoid.WalkSpeed

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Animator = Humanoid:WaitForChild("Animator")
local Animations = ReplicatedStorage:WaitForChild("Animations"):GetChildren()

local UserInputService = game:GetService("UserInputService")

local KeyCodes = {
    Enum.KeyCode.Z,
    Enum.KeyCode.X,
    Enum.KeyCode.C
}

local Combo = 0
local MaxCombo = #Animations
local LastTimeClicked = os.clock()

local Debounce = false
local Endlag = false

UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
    if GameProcessedEvent or Debounce then return end
    Debounce = true
    
    if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
        local CurrentTime = os.clock()
        
        Combo += 1
        
        task.spawn(function()
            if (Combo > MaxCombo) then
                Combo = 0

                Endlag = true
            end
        end)
        
        local AnimationTrack = Animator:LoadAnimation(Animations[Combo])

        AnimationTrack:Play()

        if (CurrentTime - LastTimeClicked > 1) then
            Combo = 0
        end
        
        LastTimeClicked = CurrentTime
    end
    
    if Input.UserInputType == Enum.UserInputType.Keyboard then
        if table.find(KeyCodes, Input.KeyCode) then
            print("Player has pressed "..Input.KeyCode.Name)
        end
    end
    
    if Endlag then
        task.delay(2.5, function()
            Debounce = false
            Endlag = false
        end)
    else
        task.delay(0.5, function()
            Debounce = false
        end)
    end
end)

The combo is always a non-negative integer greater than 0 so I don't know what's going on here

alpine cliff
vivid holly
#

But

#

It still dont work

#

Even if I remove task.spawn

alpine cliff
#

task.spawn is not the problem. The problem is Combo being set to 0 when you index the Animations array

#

Have you used the debugger + watch widget?

vivid holly
#

How I use it

alpine cliff
#

That would help you determine the nature of your problem in no time

vivid holly
#

I mean where to find

alpine cliff
# vivid holly How I use it

Drop a breakpoint on the LoadAnimation line. You can do that by hovering to the right of the line number and clicking the translucent red dot:

#

This will cause your script to trigger the debugger, which halts the execution of your script, and enables manual progression

#

Go to View and enable the Watch widget:

#

Together, you these tools allow you to step through your code line-by-line, and meticulously observe state as it changes

#

Check the relevant state, like the Animations array, its contents, and the Combo counter