#Why does the anim loop when I click?

20 messages · Page 1 of 1 (latest)

robust phoenix
#
local remotes = rp:WaitForChild("Remotes")

local combatRemote = remotes:WaitForChild("Combat")

local animations = rp:WaitForChild("Animations")
local combatAnims = animations:WaitForChild("Combat")

local Players = game:GetService("Players")

local max_combo = 5

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
    char:SetAttribute("Combo",0)
    end)
end)

local function changeCombo(char)
    local combo = char:GetAttribute("Combo")
    
    if combo < max_combo then
        char:SetAttribute("Combo", combo + 1)
    else
        char:SetAttribute("Combo", 1)
    end
end

local function getAnimation(char)
    local combo = char:GetAttribute("Combo")
    
    local anims = combatAnims:GetChildren()
    
    local currAnim = anims[combo]
    
    return currAnim
end

combatRemote.OnServerEvent:Connect(function(player)
    local char = player.Character
    local hum = char:WaitForChild("Humanoid")
    local humRp = char:WaitForChild("HumanoidRootPart")
    
    local animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator",hum)
    
    local attacking = char:GetAttribute("Attacking")
    local slicing = char:GetAttribute("Slicing")
    

    
    if attacking or slicing then return end
    
    char:SetAttribute("Attacking", true)
    char:SetAttribute("Slicing", true)
    
    changeCombo(char)

    local sliceAnim = getAnimation(char)
    local playAnimation = animator:LoadAnimation(sliceAnim)
    
    playAnimation.KeyframeReached:Connect(function(kf)
        if kf == "hit" then
            task.wait(0.21)
            char:SetAttribute("Attacking", false)
            
            if char:GetAttribute("Combo") == max_combo then
                task.wait(1.5)
            end
            
            char:SetAttribute("Slicing", false)
        end
    end)
    
    playAnimation:Play()
     
end)```
gaunt stirrup
#

.Looped property is enabled or you uploaded the animation looped.

robust phoenix
#

ah

#

yea

#

I turned off loop after I uploaded it

#

that’s probably why

gaunt stirrup
#

I don't even need to read code to answer this

robust phoenix
#

thanks

gaunt stirrup
#

Np

#

Also consider learning about modules, it can help you with systems a lot.

robust phoenix
#

okay, will do

tough iglooBOT
#

studio** You are now Level 1! **studio

gaunt stirrup
robust phoenix
#

jeez

gaunt stirrup
#

I know what I'm talking about 😭

robust phoenix
#

so do modules basically save time

gaunt stirrup
#

Yes, they give flexibility and autocomplete to functions that you may create in different scripts.

robust phoenix
#

i see

gaunt stirrup
#

Just look at examples from recently made videos online

#

I promise you'll be amazed how cool and fun they're to work with.