Scripting help... (Animation)

Please help, urgent.

I am making a fighting game, and this script is not loading correctly…

This is a script for an animation

local player = game:GetService(“Players”).LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild(“Animation”)
local swinganimation = character.Humanoid:LoadAnimation (animation)
local canSwing = true
local debounce = 1
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swinganimation:play()
wait(debounce)
canSwing = true
end
end)

This is the error
image

Thank you for any help.

İs there a error? Or what is the problem?

The animation will not work… This is the code for the animation.

Try this:


local player = game:GetService(“Players”).LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild(“Animation”)
local swinganimation = character.Humanoid:LoadAnimation(animation)
local canSwing = true
local debounce = 1
script.Parent.Activated:Connect(function()
    if canSwing then
        canSwing = false
        swinganimation:Play()
        wait(debounce)
        canSwing = true
    end
end)

@FurukanDev That script does not fix the problem… you can look at the error I made… That might be helpful.

The Character and the Humanoid don’t load in instantly, they have to load in.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
local Tool = script.Parent
local Animation = Tool:FindFirstChild("Animation") or Tool:WaitForChild("Animation")
local SwingTrack = Humanoid:LoadAnimation(Animation)
local Debounce = false
local Cooldown = 1 -- The higher the number the longer the player has to wait before using the tool again

Tool.Activated:Connect(function()
    if not Debounce then
       Debounce = true
       SwingTrack.Priority = Enum.AnimationPriority.Action -- A higher priority will override an animation of a lower priority
       SwingTrack:Play()
       wait(Cooldown)
       Debounce = false
    end
end)

The error does not look related to the script you are posting. Are you sure there’s an error?