Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i add another animation and make them keep switching every time the function is triggered?

Asked by
Echtic 128
5 years ago

Here is the script with just one animation, now i need to have another one and have the first one played the first time the function is triggered, the second one second time, then first one again etc...

wait()

local ev = script.Parent

ev.OnServerEvent:Connect(function(player)

    local dmg = game.ReplicatedStorage.Dmg:Clone()


    local anim = player.Character.Humanoid:LoadAnimation(dmg.anim)


    anim:Play()

    wait(.2)

    dmg.Parent = player.Character.RightHand

    local weld = Instance.new("Weld")
    weld.Parent = dmg
    weld.Part0 = player.Character.RightHand
    weld.Part1 = player.Character.RightHand.Dmg
    weld.C1 = CFrame.new(0,3,0)





    wait(.2)
    dmg:Destroy()


end)

1 answer

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

For that you need to use debounce and here is an example script

local ev = script.Parent
local debounce = false
local Track = nil

ev.OnServerEvent:Connect(function(player)
    local dmg = game.ReplicatedStorage:WaitForChild("dmg"):Clone()
    local Anim1 = dmg.Anim1
    local Anim2 = dmg.Anim2
    local char = player.Character or player.CharacterAdded:Wait()
    if debounce == false then
        debounce = true
        Track = char.Humanoid:LoadAnimation(Anim1)
        Track:Play()

        dmg.Parent = char.RightHand

        local weld = Instance.new("Weld")
        weld.Parent = dmg
        weld.Part0 = dmg
        weld.Part1 = char.RightHand
        weld.C1 = CFrame.new(0,3,0)
        wait(.2)

        dmg:Destroy()
    else
        debounce = false
        Track = char.Humanoid:LoadAnimation(Anim2)
        Track:Play()

        dmg.Parent = char.LeftHand

        local weld = Instance.new("Weld")
        weld.Parent = dmg
        weld.Part0 = dmg
        weld.Part1 = char.LeftHand
        weld.C1 = CFrame.new(0,3,0)
        wait(.2)

        dmg:Destroy()
    end
end)

0
I am so thankful to you! Echtic 128 — 5y
0
it worked?? HaveASip 494 — 5y
0
Perfectly! Echtic 128 — 5y
0
You are welcome :D HaveASip 494 — 5y
Ad

Answer this question