Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

4 comments

0

I am so thankful to you!

0

it worked??

0

Perfectly!

0

You are welcome :D

This discussion is preserved as it was. New answers, comments, and votes are closed.