--https://en.wikipedia.org/wiki/For_loop


local currentPlaying
localAnimationPlayer = game:GetService("ReplicatedStorage").AnimationManager.LocalScriptAPI

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") and v.Name ~= "Cancel" then
		v.AnimRef.Value = game:GetService("ReplicatedStorage").FemaleAnimations:FindFirstChild(v.Name)
	end
end

function FindAnimRef(parent)
	local childs = parent:GetChildren()
	for i, v in pairs(childs) do
		if v:IsA("ObjectValue") then
			return v.Value
		end
	end
end

for i, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			local char = game.Players.LocalPlayer.Character
			if char.Humanoid.Health > 1 then
				if currentPlaying == v then
					localAnimationPlayer.StopAnimationOnHumanoid:FireServer(char.Humanoid)
					currentPlaying = nil
				else
					local animation = FindAnimRef(v)
					if animation then
						localAnimationPlayer.PlayAnimation:InvokeServer(animation, game.Players.LocalPlayer.Character)
						currentPlaying = v
					end
				end
			end
		end)
	end
end
